Replace last main()
with main(game)
and make this small changes, remember to read the python tutorials, good luck!
import random
import math
game = int(input("How many problems do you want?\n"))
num_1 = random.randint(1,10)
num_2 = random.randint(1,10)
def main(game):
random.seed()
count = 0
correct = 0
result = 0 #Here we initialized result to 0
while count < game:
num_1 = random.randint(1,10)
num_2 = random.randint(1,10)
guess = int(input("What is " + str(num_1) + "x" + str(num_2) + "."))
answer = num_1*num_2 # Here we don't convert to string so the next "if" works
count += 1
if guess == answer:
correct += 1
print("Correct!")
if guess != answer:
print("Sorry, the answer is", answer, ".")
if game > 1:
result = correct * 100./game
print("You got ", "%.1f"%result, "of the problems.")
main(game) #send game as parameter
3
solved Need help understanding a type error