它不會告訴你問題是否正確(當它應該),並且它沒有按照它在所有問題被問到時所應該做的。它應該在最後說:「你得分」+ 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