gpt4 book ai didi

python - 我不断收到无效语法,但找不到它

转载 作者:行者123 更新时间:2023-12-01 06:20:43 27 4
gpt4 key购买 nike

if (x == True):
if (beverage_bought == True):
if (fries_bought == True):
print("You bought: " + x + " x, " + beverage + " drink, " + fries + " fries, and " +
ketchup_string + " ketchup packets.")
total = total - 1
else:
print ("You bought: " + x, " x, " + beverage + " drink, no fries and " + ketchup_string + " ketchup packets.")
elif (fries_bought == True):
print ("You bought: " + x + " x, nothing to drink, " + fries + " fries, and " + ketchup_string + " ketchup packets.")
else:
print ("You bought: " + x, " x, nothing to drink, no fries, and " + ketchup_string + "
ketchup packets.")

print (total)

它一直说我的 elif 行语法无效

最佳答案

您不能在 else 之后使用 elseifelse 必须是链的最后一个: if > elif > elif > else.

您应该删除第二个 elif 的缩进,以将其与第一个 if 对齐。

if x:
if beverage_bought:
if fries_bought:
print("You bought: " + x + " x, " + beverage + " drink, " + fries + " fries, and " + ketchup_string + " ketchup packets.")
total = total - 1
else:
print("You bought: " + x, " x, " + beverage + " drink, no fries and " + ketchup_string + " ketchup packets.")

elif fries_bought:
print("You bought: " + x + " x, nothing to drink, " + fries + " fries, and " + ketchup_string + " ketchup packets.")
else:
print("You bought: " + x, " x, nothing to drink, no fries, and " + ketchup_string + " ketchup packets.")

print(total)

关于python - 我不断收到无效语法,但找不到它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60378506/

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