小小购物车


 1 #!coding: utf-8
 2 proc_list=[
 3 ("car",100000),
 4 ("house",600000),
 5 ("E40",10000),
 6 ("bike",50000),
 7 ("mobile",20000),
 8 ("hunjia",50000)
 9 ]
10 shopping_car=[]
11 saving=raw_input("Please input your saving: ")
12 if saving.isdigit():
13   saving=int(saving)
14   while True:
15     for i,v in enumerate(proc_list,1):     #注意1,是从1开始的。枚举;
16       print (i,">>>",v)
17     choice=raw_input("Please input your choice: [q]>>is exit>>>>")
18     if choice.isdigit():
19       choice=int(choice)
20       if choice>0 and choice<=len(proc_list):
21         p_item=proc_list[choice-1]
22         if  saving>=p_item[1]:
23           saving-=p_item[1]
24           shopping_car.append(p_item)
25           print shopping_car
26           print ("您还剩余 %d 块钱" %saving)
27         else:
28           print "您的余额不足:"
29       else:
30         print "无效的编码范围"
31     elif choice=="q":
32       print "您购买的商品如下:"
33       for i in shopping_car:
34         print i
35       print ("您还剩余 %d 块钱" %saving)
36       break
37     else:
38       print "Invaild synax!"
39 else:
40   print "Error!"

能够实现存入的钱能买什么货物,钱不够了还差多少,退出时候提交购买的商品;

 

 

 

posted @ 2018-01-12 16:35  lixinliang  阅读(191)  评论(0编辑  收藏  举报