我目前正在尝试创建一个菜单来为餐厅选择食物,但不知道如何正确显示菜单。我目前对它应该如何工作的大致想法是这样的:
name = int(input ('Welcome to Dinos Cupcakes, enter your name to continue '))
cc_list = [
['1. Chocolate-dipped Maple Puff ($3.50 each)', 1, 3.50],
['2. Strawberry Twizzler ($2.25 each)', 1, 2.25],
['3. Vanilla Chai Strudel ($4.05 each) ', 1, 4.05],
['4. Honey-drizzled Lemon Dutchie ($1.99)', 1, 1.99]]
print cc_list
while #Selection does not equal 1-4 repeat list
quantity = int(input('How many would you like to purchase of this variety '))
new_quantity = quantity * #Dougnut selection
print (name, 'here is your receipt:'):
我想有这样的结束打印:
NAME这是您的收据:
-------------------------------#巧克力蘸枫泡芙------------------------------
总成本:$
谢谢你,祝你今天愉快!
不为您做任何事情。下面的内容应该足以让你到达你需要的地方。请记住,您的cc_list实际上是列表中的一个列表。要引用元素,您需要引用所选内容(1,2,3,4(,然后引用列表中的元素(0,1,2(。
这将允许您提取用户为获得字符串所做的选择和价格。有了这个,你应该能够弄清楚如何给他们一个总数,并格式化你的输出。
name = input('Welcome to Dinos Cupcakes, enter your name to continue ')
cc_list = [
['1. Chocolate-dipped Maple Puff ($3.50 each)', 1, 3.50],
['2. Strawberry Twizzler ($2.25 each)', 1, 2.25],
['3. Vanilla Chai Strudel ($4.05 each) ', 1, 4.05],
['4. Honey-drizzled Lemon Dutchie ($1.99)', 1, 1.99]]
print(cc_list)
selct = int(input("Enter a number"))
order = cc_list[selct+1][0]
cost =str(cc_list[selct+1][2])
print(name + " your stuff")
print("The total cost is " + cost)
给你,这是一个"原始"的,请使用python 3.x
name = input ('Welcome to Dinos Cupcakes, enter your name to continue ')
cc_list = [
['1. Chocolate-dipped Maple Puff ($3.50 each)', 1, 3.50],
['2. Strawberry Twizzler ($2.25 each)', 1, 2.25],
['3. Vanilla Chai Strudel ($4.05 each) ', 1, 4.05],
['4. Honey-drizzled Lemon Dutchie ($1.99)', 1, 1.99]]
print(cc_list)
selection = int(input("Please select 1-4"))
while selection not in [1,2,3,4]:
selection = int(input("Please select 1-4"))
quantity = int(input('How many would you like to purchase of this variety '))
total_cost = quantity * cc_list[selection][2]
print(f'{name}, here is your receipt:')
print(f'------------------------------- # {cc_list[selection][0]} -------------------------------')
print(f'Total cost: ${total_cost}')
print('Thank you, have a nice day!')
CMD输出:
Welcome to Dinos Cupcakes, enter your name to continue bill
[['1. Chocolate-dipped Maple Puff ($3.50 each)', 1, 3.5], ['2. Strawberry Twizzler ($2.25 each)', 1, 2.25], ['3. Vanilla Chai Strudel ($4.05 each) ', 1, 4.05], ['4. Honey-drizzled Lemon Dutchie ($1.99)', 1, 1.99]]
Please select 1-41
How many would you like to purchase of this variety 1
bill, here is your receipt:
------------------------------- # 2. Strawberry Twizzler ($2.25 each) -------------------------------
Total cost: $2.25
Thank you, have a nice day!
以下是您的修改:
name = input ('Welcome to Dinos Cupcakes, enter your name to continue: ')
cc_list = [
['1. Chocolate-dipped Maple Puff ($3.50 each)', 1, 3.50],
['2. Strawberry Twizzler ($2.25 each)', 1, 2.25],
['3. Vanilla Chai Strudel ($4.05 each) ', 1, 4.05],
['4. Honey-drizzled Lemon Dutchie ($1.99)', 1, 1.99]]
print(cc_list)
hm=0
while hm not in range(1,5):
hm = int(input('Hello {}, Which item (1-4) would you like: '.format(name)))
quantity=0
while quantity not in range(1,100):
quantity = int(input('How many would you like to purchase of this variety: '))
new_quantity = quantity * cc_list[hm-1][2]
print (name, 'here is your receipt: ', new_quantity)
以下是实现您目标的解决方案。
cc_list = [
['1. Chocolate-dipped Maple Puff ($3.50 each)', 1, 3.50],
['2. Strawberry Twizzler ($2.25 each)', 1, 2.25],
['3. Vanilla Chai Strudel ($4.05 each) ', 1, 4.05],
['4. Honey-drizzled Lemon Dutchie ($1.99)', 1, 1.99]]
name = input ('Welcome to Dinos Cupcakes, enter your name to continue: ')
print()
for item in cc_list:
print(item)
print()
choice = int(input('Your choice: '))
while choice not in range(1, 5):
choice = int(input('Your choice: '))
quantity = int(input('How many would you like to purchase of this variety: '))
prices = quantity * cc_list[choice-1][-1]
product_name = cc_list[choice-1][0]
print("n")
print('{} here is your receipt:'.format(name))
print()
print('----------- # {} -----------'.format(product_name))
print()
print("Total cost: {} $".format(prices))
print()
print("Thank you, have a nice day!")
输出:
Welcome to Dinos Cupcakes, enter your name to continue: Alexis
['1. Chocolate-dipped Maple Puff ($3.50 each)', 1, 3.5]
['2. Strawberry Twizzler ($2.25 each)', 1, 2.25]
['3. Vanilla Chai Strudel ($4.05 each) ', 1, 4.05]
['4. Honey-drizzled Lemon Dutchie ($1.99)', 1, 1.99]
Your choice: 2
How many would you like to purchase of this variety: 3
Alexis here is your receipt:
----------- # 2. Strawberry Twizzler ($2.25 each) -----------
Total cost: 6.75 $
Thank you, have a nice day!
在python3.x 中尝试这个
name = input ('Welcome to Dinos Cupcakes, enter your name to continue : ')
cc_list = [
['1. Chocolate-dipped Maple Puff ($3.50 each)', 1, 3.50],
['2. Strawberry Twizzler ($2.25 each)', 1, 2.25],
['3. Vanilla Chai Strudel ($4.05 each) ', 1, 4.05],
['4. Honey-drizzled Lemon Dutchie ($1.99)', 1, 1.99]]
for x in range(len(cc_list)):
print(cc_list[x])
selection = int(input("Please select 1-4 : "))
while selection not in [1,2,3,4]:
selection = int(input("Please select 1-4 : "))
# array start from possition 0
selection = selection - 1
quantity = int(input('How many would you like to purchase of this variety : '))
total_cost = quantity * cc_list[selection][2]
print(f'{name}, here is your receipt : ')
print(f'------------------------------- # {cc_list[selection][0]} -------------------------------')
print(f'Total cost: ${total_cost}')
print('Thank you, have a nice day!')
输出
Welcome to Dinos Cupcakes, enter your name to continue : Tim
['1. Chocolate-dipped Maple Puff ($3.50 each)', 1, 3.5]
['2. Strawberry Twizzler ($2.25 each)', 1, 2.25]
['3. Vanilla Chai Strudel ($4.05 each) ', 1, 4.05]
['4. Honey-drizzled Lemon Dutchie ($1.99)', 1, 1.99]
Please select 1-4 : 4
How many would you like to purchase of this variety : 10
Tim, here is your receipt :
------------------------------- # 4. Honey-drizzled Lemon Dutchie ($1.99) -------------------------------
Total cost: $19.9
Thank you, have a nice day!