python - 我不断收到无效的语法,但我找不到它
问题描述
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 行的语法无效
解决方案
elseif
之后不能使用else
。else
必须是链的最后一个: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 - 在 Python 中捕获的异常仍在冒泡
- python - 测试一个使用 sqlite 数据库的 Flask API
- c++ - Opengl 3d立方体不渲染
- anylogic - 减少代理的延迟
- node.js - 如何使用 vb.net 客户端连接到 node.js Websocket 服务器
- c - 在 C 中解密密码
- c# - 我不能在注册表中添加超过 10 个数字值 DWord
- django - 获取 django.contrib.staticfiles.views.serve 引发的异常
- legend - 删除饼图图例中名称和百分比之间的空格 (amcharts4)
- cuda - 如何对 CUDA 内核中的结构进行原子操作?