python饮料购买_Python自动售货机零食和饮料

嗨,伙计们,我已经尝试创建一个工作的python自动售货机一个多月了,它看起来没有任何进展。如果有人能帮我,那就太好了:)以下是我目前为止的计划:print ("Welcome to the Vending Machine\n")

total = 0

dr = 1

sn = 3

money=int(input("How much money do you want to insert"))

print ("Prices: Drinks: £1, Snacks: £3\n")

Drinks = {'Coke','Pepsi','Orange Juice', 'Apple Juice','Water'}

Snacks = {'Chocolate', 'Snickers','Twix','Peanuts','Crisp'}

state = 'subtotal'

while total <= money:

if state != 'total':

print('')

print('')

print ("\nDrinks Menue:")

print(Drinks)

print ("Snacks Menue:")

print(Snacks)

choice = input("\nEnter the item of your choice: ")

if choice in Drinks:

total += dr

elif choice in Snacks:

total += sn

else:

state = 'total'

print("\n\nThat will be a",state,"of £",total)

else:

print("You have exceeded your inserted money good bye")

我试图让代码拒绝无效的输入,并在用户超过其开销限制时停止。在

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值