0
我想爲我的妹妹做一個乘法遊戲,但是我的代碼沒有正確地通過if-else語句。我不知道爲什麼這樣。有人可以告訴我做錯了什麼嗎?If-else if statement not working properly
from random import randint
print "Welcome to Multiplication Practice."
print "\n-------"
correct = 0
wrong = 0
while wrong<3:
a = randint(1,9)
b = randint(1,9)
print "What is %s x %s?" %(a,b)
c = a * b
action = raw_input("> ")
if action == c:
print "correct!"
correct +=1
elif action != c:
print "Wrong!"
wrong +=1
else:
print "Invalid answer."
print correct
print wrong
'raw_input'返回一個字符串,乘法返回一個數字。他們永遠不會平等。 – Barmar
嘗試'action = int(raw_input(「>」))' –
這很有道理。謝謝!還有什麼我忽略的? –