here is my script:
from random import *
from turtle import *
while True:
r1 = randint(1,20)
r2 = randint(1,20)
# ... ask the question ... then
a = textinput("Answer?", "")
if a == r1 * r2:
write("Well done", font = ("Comic Sans MS", 30, "bold"))
else:
write("WRONG", font = ("Comic Sans MS", 30, "bold"))
The game is very simple. It picks too random numbers and asks you to multiply them. You get the answer right your score goes up. Get the answer wrong your score goes down. When I input the right answer it still comes up “Wrong”
I think maybe I’m doing the ifs differently or it might not be working
because of the random numbers. Has anyone got an idea what is wrong with my script. Thanks 🙂
r1 * r2is an integer.ais a string.Convert
ato integer and compare.Converting to integer is simple:
However, a
ValueErrorcan be raised and has to be handled.