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行有一个无效的语法
发布于 2020-02-24 22:59:38
在else之后不能使用elseif。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)https://stackoverflow.com/questions/60378506
复制相似问题