【发布时间】:2023-02-22 09:29:05
【问题描述】:
prices=[120,130,120,150]
menu = {
1: ["Latte", 120],
2: ["Capputino", 130],
3: ["Americano", 120],
4: ["Espresso",150]
}
headers = ["No.", 'Name', "Price"]
print(f'{headers[0]: <10}{headers[1]: <15}{headers[2]}')
for value, key in menu.items():
print(f'{value: <10}{key[0]: <15}{key[1]}')
myorder_coffee=[]
myorder_cost=[]
total=0
print("Welcome to COFFEE & DELIGHT")
name=input("Enter your name: ")
order=input("Enter the name of your order: ")
quantity=input("Enter the amount of drinks.you want to order: ")
if order=="Latte":
myorder_coffee.append(coffee[0])
myorder_cost.append(prices[0])
total=quantity*120
print(name,"ordered",quantity,"Latte")
print("Total amount to be paid=",total)
elif order=="Capputino":
myorder_coffee.append(coffee[1])
myorder_cost.append(prices[1])
total=quantity*130
print(name,"ordered",quantity,"Capputino")
print("Total amount to be paid=",total)
elif order=="Americano":
myorder_coffee.append(coffee[2])
myorder_cost.append(prices[2])
total=quantity*120
print(name,"ordered",quantity,"Americano")
print("Total amount to be paid=",total)
elif order=="Espresso":
myorder_coffee.append(coffee[3])
myorder_cost.append(prices[3])
total=quantity*150
print(name,"ordered",quantity,"Espresso")
print("Total amount to be paid=",total)
else:
print("Item not in menu")
好吧,我完全没想到会发生这种情况。
No. Name Price
1 Latte 120
2 Capputino 130
3 Americano 120
4 Espresso 150
Welcome to COFFEE & DELIGHT
Enter your name: pp
Enter the name of your order: Americano
Enter the amount of drinks. you want to order: 4
pp ordered 4 Americano
Total amount to be paid= 444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
[Program finished]]
【问题讨论】:
-
请查看how to ask page以及write a MRE。当前帖子格式不正确并且缺少一些变量声明。
-
您忘记将
quantity转换为整数,而是一个字符串。实际上将total变成了 120 '4'
标签: python dictionary