嗨,伙计们,我已经尝试创建一个工作的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")
我试图让代码拒绝无效的输入,并在用户超过其开销限制时停止。在