首页 > 代码库 > python-购物车

python-购物车

 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  
14              thinkpad $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             if money<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-购物车