它不会告诉你问题是否正确(当它应该),并且它没有按照它在所有问题被问到时所应该做的。它应该在最后说:“你得分”+ str(correctQuestions)+“/ 10个问题。” 下面是代码:Python随机数学公式不起作用
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.")
这看起来很像一个家庭作业问题。 –
@CalleDybedahl它看起来像家庭问题,我可以提出新的标签'数学测验在python'? – gboffi