侧面有两个星星的线不起作用,显示语法错误 我真的很沮丧,请帮助,应该是这样的行: 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")```
答案 0 :(得分:0)
您应该小心括号和缩进。仅当您写:
时,才应向右滑动。并且您应该关闭每个括号。另外,您的食物变量是int
,而不是str
。如果比较int
和str
,则为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")