Hey guys im on the same program as last time D: And i wondered if there was a command which can work out a mathematics question that you have asked and compare it to the answer the user has written. Obviously if its wrong it will output wrong, and right if its right. Here is my code:
import time
person=input('Hello there, what is your name? ')
print('Hello',person,'today you will test a maths quiz which is 10 questions')
time.sleep(1)
print('Good luck here is your first question:')
UserScore=0
UserWrong=0
x=0
while x<10:
import random
Ran=random.randint(1, 10)
dom=random.randint(1, 10)
Operators=[ 'plus', 'minus', 'times']
op = random.choice(Operators)
AnswerOne=input('What is '+str(Ran) +' '+str(op) +' '+str(dom) +'? ')
if int(AnswerOne) == Ran + dom:
print('Correct!')
UserScore= UserScore + 1
elif int(AnswerOne) == Ran - dom:
print('Correct!')
UserScore= UserScore + 1
elif int(AnswerOne) == Ran * dom:
print('Correct!')
UserScore= UserScore + 1
else:
print('You are wrong! Better look next time :D')
UserWrong= UserWrong +1
x=x+1
print('You got '+str(UserScore) +' right and '+str(UserWrong) +' wrong')
Aucun commentaire:
Enregistrer un commentaire