I'm solving this problem enter link description here
My code doesn't pass automated test enter link description here
import sys
import random
def main():
get_level()
def get_level():
while True:
try:
lev=int(input("Level: ",))
if lev == 1 or lev ==2 or lev == 3:
generate_integer(lev)
except ValueError:
pass
def generate_integer(level):
if level == 1 or level == 2 or level == 3:
m=0
n=0
p=0
i=0
while i<=9 :
i=i+1
if level == 1:
a=random.randint(0,9)
b=random.randint(0,9)
elif level == 2:
a=random.randint(10,99)
b=random.randint(10,99)
else:
a=random.randint(100,999)
b=random.randint(100,999)
total= a + b
c = a
d = b
try:
guess=int(input(f"{a} + {b} = ", ))
x=str(guess)
if guess != total or x.isdigit() == False :
#n=n+1
raise ValueError
except ValueError:
n=n+1
print("EEE")
p= p+1
for j in range(1):
try:
guess=int(input(f"{a} + {b} = ", ))
x=str(guess)
if guess == total:
break
elif guess != total or x.isdigit() == False:
raise ValueError
#if guess == total:
#print(f"{a} + {b} = {total} ")
#break
except ValueError:
print("EEE")
p= p+1
for k in range(1):
try:
guess=int(input(f"{a} + {b} = ", ))
x=str(guess)
if guess == total:
break
elif guess != total or x.isdigit() == False:
raise ValueError
#elif guess == total:
#print(f"{a} + {b} = {total} ")
#break
except ValueError:
print("EEE")
p= p+1
print(f"{a} + {b} = {total} ")
break
if total == guess:
m=m+1
continue
elif total != guess or p==1 or p==2 or p==3:
n=n-1
continue
print("Score:",m - n)
sys.exit(0)
if __name__ == "__main__":
main()
level
is valid before calling intogenerate_integer
you don't have to checklevel
again.. check it on one place is a best practice. not going to fix your code but will improve your code