首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我一直得到一个无效的语法,但是我找不到它

我一直得到一个无效的语法,但是我找不到它
EN

Stack Overflow用户
提问于 2020-02-24 22:56:24
回答 1查看 46关注 0票数 1
代码语言:javascript
复制
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行有一个无效的语法

EN

回答 1

Stack Overflow用户

发布于 2020-02-24 22:59:38

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

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

代码语言:javascript
复制
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)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60378506

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档