I am trying to make a maths quiz with Python and to do this I wanted to make a validation rule that meant if a user put something that was not a number, it will ask them again as it is invalid.
I tried to do this and I am coming up with the same error as I would if I did it normally. Any help?
if operator=="+":
#this is a if statement which states that if the operator is
#add then the answer should be num1 add num2 as the add function was randomly
#picked
def inputNumber(message):
while True:
try:
useranswer=int(input(actualquestion))
except ValueError:
print("This is not an integar!")
continue
else:
return usseranswer
break
actualanswer=num1 + num2 #this states that the answer is equal to the rando
#ly picked num1 add num2 as the operator is add.
if useranswer==actualanswer:
#this if function states that if the users answer is equal to the real answer
#the programme worked out before hand.
score+=1 #if the answer is right you will add 1 to the score
questions+= 1 #you will add 1 to the question also as 1 qw has been asked.