You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
When running my code for the Little Professor problem through check50, I receive all green smilies for code that outputs 10 problems and code that outputs 9 problems by changing the "while questions < 10" to "<9" and "if questions == 10" to "==9" in the code below.
After reviewing my code, I'm still not sure whether my code has an error or check50 is mistakenly suggesting the code that outputs 9 problems is correct. Any help with this would be appreciated! SPOILER
importrandomimportsysdefmain():
questions=0incorrect_answers=0whileTrue:
try:
user_level=get_level()
ifuser_level==ValueError:
passelse:
whilequestions<10:
attempts=0questions+=1generated_ints=generate_integer(user_level)
x=generated_ints[0]#x is first element of tupley=generated_ints[1]#y is second element of tuplewhileattempts<=2:
user_input=int(input(f"{x} + {y} ="))
correct_answer=x+yifuser_input!=correct_answerandattempts==2:
incorrect_answers+=1print(f"Correct Anwer: {correct_answer}")
breakelifuser_input!=correct_answer:
attempts+=1print("EEE")
else:
breakifquestions==10:
answered_correctly=10-int(incorrect_answers)
returnprint(answered_correctly)
exceptEOFError:
sys.exit("\nGoodbye.")
defget_level():
whileTrue:
try:
level=int(input("Level: "))
iflevelnotin {1,2,3}:
passelse:
returnlevelexceptValueError:
passdefgenerate_integer(level):#generate_integer returns a randomly generated non-negative integer with level digits#or raises a ValueError if level is not 1, 2, or 3:iflevelnotin {1,2,3}:
returnValueErroreliflevel==1:
x=random.randint(0,9)
y=random.randint(0,9)
returnx, yeliflevel==2:
x=random.randint(10,99)
y=random.randint(10,99)
returnx, y#elif level == "3":else:
x=random.randint(100,999)
y=random.randint(100,999)
returnx, ydeffinal_score(wrong_answers):
answered_correctly=10-int(wrong_answers)
print(f"Score: {answered_correctly}/10")
if__name__=="__main__":
main()
The text was updated successfully, but these errors were encountered:
Hi,
When running my code for the Little Professor problem through check50, I receive all green smilies for code that outputs 10 problems and code that outputs 9 problems by changing the "while questions < 10" to "<9" and "if questions == 10" to "==9" in the code below.
After reviewing my code, I'm still not sure whether my code has an error or check50 is mistakenly suggesting the code that outputs 9 problems is correct. Any help with this would be appreciated! SPOILER
The text was updated successfully, but these errors were encountered: