It doesn't tell you if the question is correct or not (when it should) and it doesn't do what it is supposed to when all of the questions have been asked. It should say this at the end: "You scored " + str(correctQuestions) + "/10 questions." Here is the code:
import random
name = input("What is your name: ")
finish = False
questionNumber = 0
correctQuestions = 0
while finish == False:
op = ['+','-','*']
choice = random.choice(op)
if questionNumber < 10 and questionNumber >= 0:
number1 = random.randrange(1,10)
number2 = random.randrange(1,10)
print((number1),(choice),(number2))
answer=int(input("What is the answer?"))
questionNumber = questionNumber + 1
if choice==("+"):
realAnswer = number1+number2
elif answer==realAnswer:
print("That's the correct answer")
correctQuestions = correctQuestions + 1
else:
print("Wrong answer")
if choice==("*"):
realAnswer = number1*number2
elif answer==realAnswer:
print("That's the correct answer")
correctQuestions = correctQuestions + 1
else:
print("Wrong answer")
if choice==("-"):
realAnswer = number1-number2
elif answer==realAnswer:
print("That's the correct answer")
correctQuestions = correctQuestions + 1
else:
print("Wrong answer")
if finish == True:
print("You scored " + str(correctQuestions) + "/10 questions.")
Aucun commentaire:
Enregistrer un commentaire