My program for little professor problem passes all the tests with check50 except one that says : "expected program to reject input, but it did not". The program prompts the user for a level and if he enters a word or anything else than a number he is prompted again, but apparently I'm missing something. What does it mean exactly by "reject the input" ?.
Here is my code :
import random
def main():
counter = 10
score = 0
while True:
try:
chosen_level = get_level()
while counter > 0:
number1 = generate_integer(chosen_level)
number2 = generate_integer(chosen_level)
guesses = 3
while guesses > 0:
try:
answer = number1 + number2
problem = int(input(f"{number1} + {number2} = "))
if problem == answer:
score += 1
break
else:
guesses -= 1
print("EEE")
except ValueError:
guesses -= 1
print("EEE")
if guesses == 0:
print(f"{number1} + {number2} = {answer}")
counter -= 1
print(f"Score: {score}")
break
except (ValueError):
pass
def get_level():
while 1 == 1:
level = int(input("Level: "))
if level == 1 or level == 2 or level == 3:
break
return level
def generate_integer(level):
if level == 1:
integer = random.randint(0, 9)
elif level == 2:
integer = random.randint(10, 99)
elif level == 3:
integer = random.randint(100, 999)
else:
raise ValueError
return integer
if __name__ == "__main__":
main()
Here is a link to the results of check50: https://submit.cs50.io/check50/21907e2decd8b5447140c0154af94f27baded5b8
Thanks for your help.