《python编程快速上手——让繁琐工作自动化》8.6.1 三明治机

《python编程快速上手——让繁琐工作自动化》8.6.1 三明治机,第1张

import pyinputplus as pyip
# Price dictionary
bread_dict = {'wheat':12, 'white':10, 'sourdough':11}
protein_dict = {'chicken': 25, 'turkey': 29, 'ham': 20, 'tofu': 10}
cheese_dict = {'cheddar': 18, 'Swiss': 16, 'mozzarella': 15}

bread_response = pyip.inputMenu(['wheat', 'white', 'sourdough'],
                                 'Bread type: \n', numbered = True)
protein_response = pyip.inputMenu(['chicken', 'turkey', 'ham', 'tofu'],
                                   'Protein type: \n',numbered = True)

cheese_response = pyip.inputYesNo('Cheese? y/n: \n')
if cheese_response == 'yes':
    cheese_type = pyip.inputMenu(['cheddar', 'Swiss', 'mozzarella'],
                                  'Cheese type: \n',
                                  numbered = True )
    sandwich_response = pyip.inputInt('How many sandwiches do you want?\n',
                                      min=1)
    total_price = sandwich_response *(bread_dict[bread_response] +
                                      protein_dict[protein_response]+
                                      cheese_dict[cheese_type])
else:
    sandwich_response = pyip.inputInt('How many sandwiches do you want?\n',
                                      min=1)
    total_price = sandwich_response *(bread_dict[bread_response] +
                                      protein_dict[protein_response])

other_response = pyip.inputYesNo('Need mayo/mustard/lettuce/tomatto? \n')



print('Total price is', total_price)

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/918264.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-16
下一篇 2022-05-16

发表评论

登录后才能评论

评论列表(0条)

保存