我有一个任务,我必须做一个组合菜单。基本上我必须符合这些标准。 迭代1 向用户索要一种三明治(鸡肉5.25美元,牛肉6.25美元,豆腐5.75美元)。 让程序输出用户三明治选择,以帮助验证程序是否正确工作。 迭代2 将以下特性添加到第一次迭代中。 询问用户是否需要饮料(是,不是)。 如果他们说是,问他们想要多大的饮料: 小:$ 1.00 介质:$ 1.75 大:2.25美元 有程序输出用户饮料大小选择,或缺少选择,以帮助验证程序是否正确工作。 让程序输出到目前为止的总成本。 我刚接触Python,我真的不知道如何简单地使用这个程序。
if sandwich=='Chicken':
print "Okay! So a chicken sandwich, your total cost is $5.25"
if sandwich=='Beef':
print 'Okay! So a beef sandwich, your total cost is $6.25'
if sandwich=='Tofu':
print 'Okay! So a tofu sandwich, your total cost is $5.75'
beverage= raw_input("Would you like a beverage? Yes or No? ")
if beverage=='Yes':
size_beverage= raw_input("What size? Small, Medium, or Large? ")
if size_beverage=='Small':
if sandwich=='Chicken':
print 'Your total is $6.25'
print 'Okay! so a', sandwich,'sandwich and a small beverage'
if sandwich=='Beef':
print 'Your total is $7.25'
print 'Okay! so a',sandwich,'sandwich and a small beverage'
if sandwich=='Tofu':
print 'Your total is $6.75'
print 'Okay! so a', sandwich,'sandwich and a small beverage'
if size_beverage=='Medium':
if sandwich=='Chicken':
print 'Your total is $7'
print 'Okay! so a', sandwich,'sandwich and a medium beverage'
if sandwich=='Beef':
print 'Your total is $8'
print 'Okay! so a',sandwich,'sandwich and a medium beverage'
if sandwich=='Tofu':
print 'Your total is $7.50'
print 'Okay! so a', sandwich,'sandwich and a medium beverage'
if size_beverage=='Large':
if sandwich=='Chicken':
print 'Your total is $7.50'
print 'Okay! so a', sandwich,'sandwich and a large beverage'
if sandwich=='Beef':
print 'Your total is $8.50'
print 'Okay! so a',sandwich,'sandwich and a large beverage'
if sandwich=='Tofu':
print 'Your total is $8'
print 'Okay! so a', sandwich,'sandwich and a large beverage'
if beverage=='No':
print 'Okay! so just a', sandwich,"sandwich?"```
问题来源StackOverflow 地址:/questions/59383978/how-to-simplify-program-python
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。