Python implementation of an automated beverage program code sharing
- 2020-04-02 14:00:54
- OfStack
When I wrote this program, I had been learning Python for nearly 100 hours. I saw someone on CSDN asking me how to write a soft drink vending program in Python. Of course, just achieve the basic function, welcome the master to give directions, the novice study reference.
Running environment: Python 2.7
# encoding=UTF-8
loop=True
money=0
while loop:
x = raw_input(' Tip: please put in gold COINS , Please press close "q" key ')
if x=='q':
if money==0:
print ' Error: you have not put in a banknote, please put in at least one banknote before you buy the goods '
else:
print ' Tip: you have finished the coin, will enter the purchase of goods operation interface '
loop = False
else:
try:
x = int(x)
money+=x
print ' Hint: you will pay this time ',x,' B: RMB yuan, your total coin ',money,' RMB '
except Exception,e:
print ' Error: your gold coin system does not recognize, please re-coin, thank you! '
GoodList = {
' Coca-Cola ':2.5,
' pulpy ':3,
' Milk tea ':1.5,
' Add the stupa ':4
}
i=0
print ' Please select commodities: '
for x in GoodList:
i+=1
print ' Serial number ',i,' Name of commodity ',x,' The price ',GoodList[x]
print
fanwei = range(len(GoodList))
loop = True
while loop:
o = raw_input(' Tip: please enter the product number you want to buy, press "q" Key end purchase ')
if o=='q':
loop = False
else:
try:
o = int(o)
if o>=1 and o<=len(GoodList):
i=0
for x in GoodList:
i+=1
if i==o:
if money>=GoodList[x]:
money -= GoodList[x]
print ' Hint: the item you purchased is :',x,' , the price :',GoodList[x],' , you still have: ',money,' RMB '
if money==0:
loop = False
else:
print ' Error: your balance ',money,' Yuan is not enough to buy the goods ',x,'[',GoodList[x],' yuan ]'
else:
print ' Error: the item number you entered does not exist. Please enter it again '
except Exception,e:
print ' Error: please enter the correct product number, thank you for your cooperation! '
if money>0:
print ' Hint: the system will find you. ',money,' RMB, welcome next time '
else:
print ' Tip: your balance has been used up. Please come next time '