PyinputPlus模块在麦当劳店三明治点餐计费的应用

PyInputPlus是一个第三方模块,类似于input,但是又很多强大的功能。

import pyinputplus as pyip
import sys

response=pyip.inputYesNo("欢迎来到麦当劳店,很高兴为你服务,现在三明治特价,请问您需要吗(Y/N)?:")
if response=="no":
    print("欢迎再次光临!")
    sys.exit()
    
breadPrice = {'全麦面包':7, '白面包':5, '酸面包':8}
proteinPrice = {'鸡肉':4, '火鸡':5, '火腿':3, '豆腐':2}
cheesePrice = {'切达奶酪':3, '瑞士奶酪':4, '马苏里拉奶酪':3}
otherPrice = {'蛋黄酱':1, '芥末':1, '生菜':1, '番茄片':1}

paySum = 0

breadType = pyip.inputMenu( ['全麦面包', '白面包', '蒜面包'], numbered=True,prompt="请选择面包类型:\n")
paySum+=breadPrice[breadType]

proteinType = pyip.inputMenu( ['鸡肉', '火鸡', '火腿','豆腐'], numbered=True,prompt="请选择蛋白质类型:\n")
paySum+=proteinPrice[proteinType]

cheeseRes=pyip.inputYesNo("是否需要奶酪(Y/N)?:")
if cheeseRes=="yes":
    cheeseType=pyip.inputMenu( ['切达奶酪', '瑞士奶酪', '马苏里拉奶酪'], numbered=True,prompt="请选择奶酪类型:\n")
    paySum+=cheesePrice[cheeseType]                      

mayoRes = pyip.inputYesNo('是否添加蛋黄酱(Y/N)?:')
if mayoRes == 'yes':
    paySum+=otherPrice["蛋黄酱"]

mustardRes = pyip.inputYesNo('是否添加芥末(Y/N)?:')
if mustardRes == 'yes':
    paySum+=otherPrice["芥末"]

lettuceRes = pyip.inputYesNo('是否添加生菜(Y/N)?:')
if lettuceRes == 'yes':
    paySum+=otherPrice["生菜"]

tomatoRes = pyip.inputYesNo('是否添加番茄片(Y/N)?:')
if tomatoRes == 'yes':
    paySum+=otherPrice["番茄片"]

sandwichNum = pyip.inputInt('需要几个三明治?: ', min=1)

paySum*=sandwichNum
print(f"\n本次一共消费{paySum}元")

运行情况如下:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值