dimanche 22 février 2015

how do i make my python code work? random math quiz

This is my code it has to have + - * in the code and it has to be chosen randomly but it does not work it does not say the correct answer I would appreciate any help thanks.



import random
import operator
question_number = 0
score = 0

ops = {'+':operator.add,
'-':operator.sub,
'*':operator.mul,
'/':operator.truediv}
number1 = random.randint(0,12)
number2 = random.randint(1,10)
op = random.choice(list(ops.keys()))

print ("this is a short maths quiz")
name = input ("what is your name")
age = input ("how old are you " +name)
print ("ok "+name+" im going to start the quiz now")
print(number1, op, number2)
user_input=int(input())
answer = (number1,op,number2)
if user_input == answer:
print("Well done")
score = score + 1

else:
print("WRONG!")
print("The answer was",answer)

question_number = question_number + 1




Aucun commentaire:

Enregistrer un commentaire