When I run locally the program behaves as I think it should. But when I run it through check50 it fails saying that I dont reject inputs that I should reject.
import random
def main():
while True:
try:
level = int(input("Level: "))
except ValueError:
continue
if get_level(level):
generate_integer(level)
break
def get_level(l):
level_list = [1, 2, 3]
if l in level_list:
return True
else:
return False
def generate_integer(level):
correct = 0
x = 0
while x < 10:
tries = 1
if level == 1:
num_1 = random.randint(1, 9)
num_2 = random.randint(1, 9)
while tries <= 3:
try:
ans = int(input(f"{num_1} + {num_2} = "))
if ans == num_1 + num_2:
correct += 1
x += 1
break
else:
print("EEE")
tries += 1
if tries == 4:
print(f"{num_1} + {num_2} = {num_1 + num_2}")
x += 1
break
except ValueError:
tries += 1
if tries == 4:
print(f"{num_1} + {num_2} = {num_1 + num_2}")
x +=1
break
else:
print ("EEE")
elif level == 2:
num_1 = random.randint(10, 99)
num_2 = random.randint(10, 99)
while tries <= 3:
try:
ans = int(input(f"{num_1} + {num_2} = "))
if ans == num_1 + num_2:
correct += 1
x += 1
break
else:
print("EEE")
tries += 1
if tries == 4:
print(f"{num_1} + {num_2} = {num_1 + num_2}")
x += 1
break
except ValueError:
tries += 1
if tries == 4:
print(f"{num_1} + {num_2} = {num_1 + num_2}")
x +=1
break
else:
print ("EEE")
elif level == 3:
num_1 = random.randint(100, 999)
num_2 = random.randint(100, 999)
while tries <= 3:
try:
ans = int(input(f"{num_1} + {num_2} = "))
if ans == num_1 + num_2:
correct += 1
x += 1
break
else:
print("EEE")
tries += 1
if tries == 4:
print(f"{num_1} + {num_2} = {num_1 + num_2}")
x += 1
break
except ValueError:
tries += 1
if tries == 4:
print(f"{num_1} + {num_2} = {num_1 + num_2}")
x +=1
break
else:
print ("EEE")
print (f"Score: {correct}")
if __name__ == "__main__":
main()