I am doing the little professor problem set. Here is my code:
import random
def main():
l = get_level()
score = 0
for i in range(10):
n1 = generate_integer(l)
n2 = generate_integer(l)
guesses = 3
while guesses > 0:
guess = input(str(n1)+" + "+str(n2)+" = ")
if guess == str(n1 + n2):
score += 1
break
else:
print("EEE")
guesses -= 1
if guesses == 0:
print(str(n1)+" + "+str(n2)+" = "+str(n1+n2))
print("Score: "+str(score))
def get_level():
while True:
l = input("Level: ")
if l.isnumeric():
if 0 < int(l) <= 3:
return int(l)
def generate_integer(level):
if level == 1:
return random.randrange(0, 9)
elif level == 2:
return random.randrange(10, 99)
else:
return random.randrange(100, 999)
if __name__ == "__main__":
main()
And my checks look like:
Results for cs50/problems/2022/python/professor generated by check50 v3.3.11
:) professor.py exists
:) Little Professor rejects level of 0
:) Little Professor rejects level of 4
:) Little Professor rejects level of "one"
:) Little Professor accepts valid level
:) At Level 1, Little Professor generates addition problems using 0–9
:) At Level 2, Little Professor generates addition problems using 10–99
:) At Level 3, Little Professor generates addition problems using 100–999
:( Little Professor generates 10 problems before exiting
timed out while waiting for program to exit
:| Little Professor displays number of problems correct
can't check until a frown turns upside down
:| Little Professor displays EEE when answer is incorrect
can't check until a frown turns upside down
:| Little Professor shows solution after 3 incorrect attempts
can't check until a frown turns upside down
To see more detailed results go to https://submit.cs50.io/check50/eeff9b18516dcb839d9c0fd50c2d64a0d2b86dc8
It looks like my code is not generating ten problems before exiting. However when I test my code it generates ten problems and displays my score. Yet I am still not passing the check.
Any ideas would be appreciated!