【问题标题】:Invalid syntax on an easy if/else statement简单 if/else 语句的语法无效
【发布时间】:2022-12-03 18:58:19
【问题描述】:
def cake(people):
    chocolate = 20
    flour = 20
    butter = 20
    people = int(input("give a number")
        if(people > 0):
            print(chocolate == chocolate*people)
            print(flour == flour*people)
            print(butter == butter*people)
        else: 
            print("nothing")
                return(chocolate, flour, butter)

大家好, 我最近开始学习 python 语言,我试图将这个函数作为练习,但是我在 if 语句的括号后的冒号空间有一个无效的语法。

我该怎么做才能解决这个问题?

预先感谢您的回答

【问题讨论】:

    标签: python-3.x


    【解决方案1】:

    people = int(input("give a number") 好像少了一个括号! Python 假设它会继续,但它发现了一个 IF 语句,因此发现了错误。还要记住修复缩进,因为 Python 解释器可能会对它挑剔。取消选中 if-else 块以及 return 语句。希望这可以帮助!

    【讨论】: