繼承人我的代碼片段。它不會說用戶不正確。每個問題的答案在列表中以相同的順序排列。在Python中遇到隨機數問題
題庫
questions = ["45 - 20","32 - 12","54 + 41"]
# Answer Bank
answers = ["25","20","95"]
while qleft != 0:
# Get random question
qnumber = randint(0,2)
currentquestion = questions[qnumber]
currentanswer = answers[qnumber]
# Question
userchoice = int(input("What does {} equal? ".format(currentquestion)))
# Check Answer
if userchoice != currentanswer:
print("Incorrect")
qleft -= 1
elif userchoice == currentanswer:
print("Correct")
qleft -= 1
else:
print("That's not a valid answer")
看起來像'integer!= string'對我來說經典的例子... – Shadow