如何修复代码中的语法错误?

2024-04-24 09:04:08 发布

您现在位置:Python中文网/ 问答频道 /正文

旁边有两颗星星的那条线不起作用,它说语法错误 我真的很沮丧,请帮忙,如果食物==(“1”):

#Python tutorials
import sys# allows the exit function
import time

#Menu
print("************MAIN MENU**************")
time.sleep(1)
choice = input("""
                      A: Add an item
                      B: Delete an Item
                      C : Checkout
                      Q: Quit/Log Out

                      Please enter your choice: """)


#Adding
if choice == "A" or choice =="a":
    print("Choose from following numbers, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12")
    food = int(input("1,12")
        **if food == ("1"):**
               print("You want to add the All day (large) Breakfast")
               time.sleep(0.5)
               print("Add another item?")
               time.sleep (0.5)
               print("To add another item just type the number")
        elif food == ("2"):
            print ("You want to add the All day (small) Breakfast")
            time.sleep(0.5)
            print("Add another item?")
            time.sleep (0.5)
            print("To add another item just type the number") 
elif choice == "B" or choice =="b":
    print("Choose from following numbers, 1, 2, 3, 4, 5,6 ,7, 8, 9, 10, 11, 12")
elif choice=="C" or choice=="c":
    print ("Are you sure?")
elif choice=="Q" or choice=="q":
    print ("your mom")```



Tags: ortheimportanaddinputtimefood
1条回答
网友
1楼 · 发布于 2024-04-24 09:04:08

你应该小心处理括号和缩进。只有在写:时,才应该向右滑动。你应该关闭你打开的每一个括号。食物变量也是int,而不是str。如果比较任何intstr,它将是False。 这是有效代码:

if choice == "A" or choice =="a":
    print("Choose from following numbers, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12")
    food = int(input("1,12"))
    if food == 1:
           print("You want to add the All day (large) Breakfast")
           time.sleep(0.5)
           print("Add another item?")
           time.sleep (0.5)
           print("To add another item just type the number")
    elif food == 2:
        print ("You want to add the All day (small) Breakfast")
        time.sleep(0.5)
        print("Add another item?")
        time.sleep (0.5)
        print("To add another item just type the number") 
elif choice == "B" or choice =="b":
    print("Choose from following numbers, 1, 2, 3, 4, 5,6 ,7, 8, 9, 10, 11, 12")
elif choice=="C" or choice=="c":
    print ("Are you sure?")
elif choice=="Q" or choice=="q":
    print ("your mom")

相关问题 更多 >