####自动购买机
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("请重新输入")