I have this code that will randomly generate an equation check the answer and keep going for one minute. The last thing that I want to add I a part that will check how many answers they input correct and wrong and print it at the end. I have tried to make it do that at the same time that it prints if the answer was correct or wrong it would also add one to a variable but I could not get that to work. Thanks
import random
import time
correct=0
wrong=0
def random_problem(num_operations):
eq = str(random.randint(1, 100))
for _ in range(num_operations):
eq += random.choice(["+"])
eq += str(random.randint(1, 100))
return eq
start = time.time()
while True:
elapsed = time.time() - start
if elapsed > 60:
print(correct,wrong)
break
problem = random_problem(1)
ask=int(input(problem +": "))
solution = eval(problem)
if ask == solution:
correct=correct+1,print("Correct")
else:
wrong=wrong+1,print("Wrong, the correct answer is",solution)
This code does not work because it is only running the first part of the if command.