I've made some corrections, the answers for CHECK 50 are the same though. I'm not getting it, the workability of the code is fine (working as expected, even when testing by 'How to Test' section). I really do need some light in here.
(Original post + (NEW) code): I know there are many questions in here with similar problems. But I want to understand what it's wrong with my coding as I've been trying many different approaches and nothing seems to solve it.
The thing is, I've had "correct" output as follows:
Level: 0
Level: 4
Level: one
Level: ,
Level: 1
0 + 8 = 1
EEE
0 + 8 = 1
EEE
0 + 8 = 1
EEE
0 + 8 = 8
5 + 5 = 1
EEE
5 + 5 = 10
6 + 7 = 13
3 + 0 = 3
8 + 0 = 8
2 + 4 = 6
4 + 0 = 4
4 + 1 = 5
3 + 4 = 7
1 + 1 = 2
Score: 8
Still, it returns the following result from "Check 50":
:) professor.py exists
:( 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
My (NEW) code is as follows:
import random
def main():
level = int(get_level("Level: "))
score = 0
for i in range(10):
error = 1
x, y = generate_integer(level)
z = x + y
while True:
print(f"{x} + {y} = ", end="")
answer = input()
if answer == str(z):
score += 1
break
elif answer != str(z) and error < 3:
print("EEE")
error += 1
continue
else:
print("EEE")
print(f"{x} + {y} = {z}")
break
print(f"Score: {score}")
def get_level(n):
while True:
level = input(n)
if level not in ['1', '2', '3']:
continue
return level
def generate_integer(l):
if l == 1:
x = random.randint(0, 9)
y = random.randint(0, 9)
elif l == 2:
x = random.randint(10, 99)
y = random.randint(10, 99)
elif l == 3:
x = random.randint(100, 999)
y = random.randint(100, 999)
return (x, y)
if __name__ == "__main__":
main()