What function do i use to generate 10 questions? I've already generated one question, however it just stops after it's answered. Its part of a maths quiz. And also how to add score each time answer is correct?
import random
ops = ['+', '-']
num1 = random.randint(0,9)
num2 = random.randint(0,9)
operation = random.choice(ops)
print(num1, operation, num2, '= ?')
answer = (input) ("What is your answer?")
maths = eval(str(num1) + operation + str(num2))
if answer ==(repr(maths)):
print("correct")
else:
print("Incorrect! The correct answer is",(maths))
Aucun commentaire:
Enregistrer un commentaire