繁体   English   中英

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

[英]How do I fix the syntax error in my code?

旁边有两颗星的那行不起作用,它说语法错误这真的让我很沮丧,请帮忙,应该是说if food == ("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")```


你应该小心括号和缩进。 只有当你写:时,你才应该向右滑动。 你应该关闭你打开的每个括号。 您的食物变量也是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")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM