gpt4 book ai didi

python - 我的 if else 语句中的语法错误

转载 作者:行者123 更新时间:2023-12-01 05:24:42 25 4
gpt4 key购买 nike

在这组代码的最后一个 else 中,我不断收到语法错误,但我不知道为什么。这不是一个间隔其语法的错误,所以我不明白我做错了什么。我想知道是否有人可以帮忙。代码如下。

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com