import random
def main():
level = get_level("Level: ")
correct_count = 0
for _ in range(10):
x = generate_integer(level)
y = generate_integer(level)
correct = x + y
attempt = 0
while attempt < 3:
x1=input(f"{x} + {y} = ")
try:
if int(x1) == correct:
correct_count += 1
break
else:
print("EEE")
attempt += 1
except ValueError:
print("EEE")
attempt += 1
if attempt == 3:
print(f"{x} + {y} = {correct}")
print(f"{correct_count}")
def get_level(x):
while True:
try:
level = int(input(x))
if level in [1,2,3]:
break
else:
raise ValueError
except ValueError:
pass
return level
def generate_integer(level):
if level == 1:
min_digits = 0
max_digits = 9
return random.randint(min_digits, max_digits)
else:
min_digits = 10 ** (level - 1)
max_digits = (10 ** level) - 1
return random.randint(min_digits, max_digits)
if __name__ == "__main__":
main()
it's failing all the check in cs50
:( Little Professor rejects level of 0
expected program to reject input, but it did not
:( Little Professor rejects level of 4
expected program to reject input, but it did not
:( Little Professor rejects level of "one"
expected program to reject input, but it did not
:( Little Professor accepts valid level
expected exit code 0, not 1
:| At Level 1, Little Professor generates addition problems using 0–9
can't check until a frown turns upside down
:| At Level 2, Little Professor generates addition problems using 10–99
can't check until a frown turns upside down
:| At Level 3, Little Professor generates addition problems using 100–999
can't check until a frown turns upside down
:| 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