问题陈述要求我编写一个程序,使用PyInputPlus询问用户的三明治偏好。使用inputMenu获取面包、蛋白质信息。输入不用于奶酪顶部,输入获取三明治数量。最后根据所有选择计算三明治的成本。提出你自己的价格。 如何改进我的程序。这个程序只适用于一种奶酪和一种配料。我应该做什么样的改变才能让程序计算出多种奶酪和配料的总数
import pyinputplus as pypi
prices = {'Bread':{'Wheat':2, 'White':2, 'Sourdough':3},
'Protein':{'Chicken':2, 'Turkey':3, 'Ham':3, 'Tofu':2},
'Cheese':{'Cheddar':1, 'Swiss':1, 'Mozzerella':1},
'Topping':{'Mayo':0, 'Mustard':0,'Lettuce':1, 'Tomato':1}}
totalPrice = []
bread = pypi.inputMenu(['Wheat','White','Sourdough'],prompt="What kind of Bread would you like?\n",default=None, caseSensitive=False)
breadPrice = prices['Bread'][bread]
totalPrice = breadPrice
protien = pypi.inputMenu(['Chicken', 'Turkey','Ham','Tofu'],prompt="What kind of protein would you like?\n",default=None, caseSensitive=False)
totalPrice += prices['Protein'][protien]
cheese = pypi.inputYesNo("Do you want cheese? Yes/No:\n ", yesVal="yes", noVal="no", caseSensitive=False, default=None, blank=False,)
if cheese == 'yes':
kindofcheese = pypi.inputMenu(['Cheddar', 'Swiss', 'Mozzerella'],prompt="What kind of cheese would you like?\n",default=None, caseSensitive=False)
totalPrice += prices['Cheese'][kindofcheese]
else:
print('No cheese selected')
topping = pypi.inputYesNo("Do you want any toppings? Yes/No:\n", yesVal="yes", noVal="no", caseSensitive=False, default=None, blank=False)
if topping == 'yes':
kindoftopping=pypi.inputMenu(['Mayo', 'Mustard','Tomato','Lettuce'], prompt="What kind of topping would you like?\n",default=None,caseSensitive=False)
totalPrice+=prices['Topping'][kindoftopping]
else:
print('No topping selected')
Qty = pypi.inputInt(prompt="How many sandwiches would you like?\n", default=1, blank=False,min=1, lessThan=5)
totalPrice = totalPrice*Qty
print(f"The total amount payable for your sandwich(es) is {totalPrice}")
您可以使用while循环添加奶酪/配料,直到用户输入no。 这是奶酪的代码,相应地修改浇头的代码
相关问题 更多 >
编程相关推荐