####自动购买机
drinks={"1":"3.5","2":"4","3":"2","4":"4.5"}
m=['1','5','10']
toubi=0
total=0
while True:
choose=input("请选择您需要的饮料:1:橙汁 2:椰汁 3:矿泉水 4:早餐奶,按Q退出")
if choose in drinks.keys():
total=total+ float(drinks[choose])
break
elif choose=="Q":
print("退出饮料选择")
break
else:
print("输入错误")
while True:
money=input("请选择面值是 1/5/10的纸币或硬币进行购买")
if money in m:
toubi=toubi+int(money)
if toubi==total:
print("投入的金额正好")
break
if toubi>total:
print("你购买了{}元的饮料,已投币{},还找零{}".format(total,toubi,toubi-total))
break
if toubi <total:
print("你购买了{}元的饮料,已投币{},还需投币{}".format(total, toubi, total-toubi))
break
else:
print("请重新输入")

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
  • 2021-11-27
  • 2022-02-05
  • 2021-06-26
  • 2021-09-01
  • 2022-03-07
猜你喜欢
  • 2022-12-23
  • 2022-02-13
  • 2022-12-23
  • 2021-04-11
  • 2021-09-05
  • 2022-12-23
  • 2021-11-23
相关资源
相似解决方案