AWS Cloud9中的If else其他语法问题[关闭]

问题描述 投票:0回答:1

我正在做学校作业,我们正在学习Python。我在使用if else else语法时遇到了一些麻烦,在我将其修复之前,我不想继续。我们曾经做过的所有if if else练习都是在整数上,但是我使用的是float输入。我们在Python 3上使用AWS Cloud9进行编码。我的代码:

chicken = 5.25
beef = 6.25
tofu = 5.75
sandwich = float(input(print("Would you like chicken, beef or tofu?: ")))
**if sandwich = "chicken":**
    print("Chicken? Your total is 5.25")
elif sandwich = "beef"
    print("Beef? Your total is 6.25")
elif sandwich = "tofu"
    print("Tofu? Your total is 5.75")
else: print("Not on the menu!")

粗体字是每次都给我的语法错误。

python syntax
1个回答
0
投票

您不见了:在elif和else语句的末尾以及未使用==,请尝试将其添加为:

chicken = 5.25
beef = 6.25
tofu = 5.75
sandwich = float(input(print("Would you like chicken, beef or tofu?: ")))
if sandwich == "chicken":
    print("Chicken? Your total is 5.25")
elif sandwich == "beef":
    print("Beef? Your total is 6.25")
elif sandwich == "tofu":
    print("Tofu? Your total is 5.75")
else: 
    print("Not on the menu!")
© www.soinside.com 2019 - 2024. All rights reserved.