簡體   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