python-購物車
阿新 • • 發佈:2017-07-17
%d multi mon spl 重新 %20 span utf think
1 #!/usr/bin/python 2 #coding=utf-8 3 import multiprocessing 4 5 str= "歡迎來到菜鳥購物系統!" 6 print str.center(80) 7 money=input("請輸入您的預算:",) 8 def show(): 9 print ‘‘‘本商城提供以下商品: 10 kindle $300 11 mac $500 12 apple $450 13 mp3 $30 14thinkpad $800 ‘‘‘ 15 show() 16 d={‘kindle‘:300,‘mac‘:500,‘mp3‘:30,‘thinkpad‘:800,‘apple‘:450} 17 18 def shop(money): 19 d1={} 20 for i in d: 21 if money>d[i]: 22 d1[i]=d[i] 23 print d1 24 print "您可以購買的商品為:" 25 for i in d1: 26 print " "*12, 27 print"%-9s$%d"%(i,d1[i]) 28 k=raw_input("請輸入你要購買的商品>>>",) 29 l=k.split(‘ ‘) 30 print l 31 for i in l: 32 if i not in d: 33 print "Input Error!" 34 k=raw_input("請重新輸入:",) 35 l=[] 36 l=k.split(‘ ‘) 37 else: 38 ifmoney<d[i]: 39 print "余額不足!" 40 break 41 money-=d[i] 42 print "您購買的商品為:" 43 for i in range(len(l)): 44 print "%20s" %(l[i]) 45 46 print "您的余額還有%d,是否繼續[y/n]?"%money 47 k=raw_input() 48 if k=="y" or k=="Y": 49 shop(money) 50 elif k=="n" or k=="N": 51 print "感謝光臨,祝您生活愉快!" 52 exit 53 else:print "輸入錯誤,請輸入y或n,不區分大小寫!" 54 shop(money)
python-購物車