For CS50P's Week 4 problem set Professor, my code appears to work fine when I test it, but check50 disagrees:
:) 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
Did not find "6 + 6 =" in "Level: 7 + 7 =..."
:) 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
can't check until a frown turns upside down
:| 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
I don't understand this, as my code functions fine:
❯ python3 professor.py
Level: 1
6 + 6 = 12
7 + 5 = 12
1 + 2 = 3
7 + 2 = 10000
EEE
7 + 2 = 10000
EEE
7 + 2 = 10000
EEE
7 + 2 = 9
2 + 1 =
etc.
Can anyone spot the problem? Here's my code.
import random
def main():
n = get_level()
score = 0
for _ in range(10):
fails = 0
x, y = generate_integer(n), generate_integer(n)
while True:
if fails == 3:
print(f"{x} + {y} = {x+y}")
break
try:
answer = int(input(f"{x} + {y} = "))
except ValueError:
fails += 1
print("EEE")
else:
if answer == x + y:
score += 1
break
else:
fails += 1
print("EEE")
print(f"Score: {score}")
def get_level():
while True:
try:
n = int(input("Level: "))
if n not in [1, 2, 3]:
continue
except ValueError:
pass
else:
return n
def generate_integer(n):
return random.randint(10 ** (n - 1), 10**n - 1)
if __name__ == "__main__":
main()
level=1
,generate_integer(n)
should return values between 0-9.