简体   繁体   中英

How do I fix the syntax error in my code?

The line with two stars on the side is not working, it says syntax error It is really frustrating me please help, it should be the line that says 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")```


You should be carefully about parentheses and indentation. Only if you write : , you should slide to the right. And you should close every parentheses you opened. Also your food variable is int , not str . If you compare any int and str it will be False . This is valid code:

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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