【发布时间】:2015-05-05 07:10:32
【问题描述】:
当我运行程序时,我会输入正确答案,但它总是将其标记为错误:
(10, '+', 2)
12
...
错误答案,答案是 12 !
这是错误的代码部分:
Player_answer = input()
print ("...")
time.sleep (0.5)
if operation==("+"): #check answer
answer = num1+num2 #This works out the real answer
if Player_answer == answer: #This works out if the player is correct
print("That's the correct answer")
score = score + 1
else:
print("Wrong answer, the answer was",answer,"!")
if operation==("*"):
answer = num1*num2
if Player_answer == answer:
print("That's the correct answer")
score = score + 1
else:
print("Wrong answer, the answer was",answer,"!")
elif operation==("-"):
answer = num1-num2
if Player_answer == answer:
print("That's the correct answer")
score = score + 1
else:
print("Wrong answer, the answer was",answer,"!")
【问题讨论】:
-
试试
if int(Player_answer) == answer -
检查您从玩家那里得到的答案类型。添加打印类型(Player_answer)
标签: variables python-3.x