在这组代码中,我在其他代码中始终遇到语法错误,我也不知道为什么。间隔正确的语法并不是一个错误,所以我不明白我在做什么错。我想知道是否有人可以提供帮助。代码如下。
if pcolor == winner:
print ('Correct!')
while player == correct:
phl = input('Higher or lower?').strip().lower()
randcard = computer_pick_card()
if randcard == 'A':
player = correct
print ('The card was an Ace')
print ('Correct!')
else:
if last_card != ():
if phl == higher:
if randcard >= last_card:
player = correct
print ('The card was ', randcard)
print ('Correct!')
elif randcard < last_card:
player != correct
print ('The card was ', randcard)
print ('You lose')
elif phl == lower:
if randcard >= last_card:
player != correct
print ('The card was ', randcard)
print ('You lose')
elif randcard < last_card:
player == correct
print ('The card was ', randcard)
print ('Correct!')
else:
if phl == higher:
if randcard >= card2:
player = correct
print ('The card was ', randcard)
print ('Correct!')
elif randcard < card2:
player != correct
print ('The card was ', randcard)
print ('You lose')
elif phl == lower:
if randcard > card2:
player != correct
print ('The card was ', randcard)
print ('You lose')
elif randcard <= card2:
player == correct
print ('The card was ', randcard)
print ('Correct!')
last_card = randcard
return last_card
last_card = ()
else:
print ('You lose')
最佳答案
在python中,间距是语法。
您没有正确的间距。
if ...
...
last_card = ()
else:
...
应该
if ...
...
last_card = ()
else:
...
关于python - 我的if else语句中的语法错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21653332/