首页 > 代码库 > 简单的购物车小程序

简单的购物车小程序

 1 # -*- coding:utf-8 -*-
   #简单的购物车小程序   author:李学松
 2 shopping_cart =[]
 3 product_list_tatol = "---product list----"
 4 welcome = "-----------welcome to shopping marketi----------"
 5 product_list = [
 6     (iphone,5800),
 7     (lenovo,900),
 8     (car,12),
 9     (thinkpad,4500),
10     (notebook,6)
11 ]
12 print welcome
13 salary = raw_input("input your salary:>>>")
14 if salary.isdigit():
15     salary = int(salary)
16 while True:
17     print product_list_tatol
18     for item in product_list:
19         print product_list.index(item)+1,item
20     choice = raw_input("choice you want to buy:>>> ___   0 to exit")
21     if choice.isdigit():
22         choice = int(choice)
23     if choice > 5 or choice < 0:
24         print  "no this goods,请重新选择"
25         continue
26     elif choice <=5 and choice >=1:
27         if salary < product_list[choice-1][1]:
28             print "账户余额不足,请购买其他商品或者退出"
29             continue
30         else:
31             pass
32         item_choice = product_list[choice-1]
33         shopping_car.append(item_choice)
34         print "you buy goods is", shopping_car
35         salary = salary - product_list[choice-1][1]
36         print "your balance is %d"%(salary)
37 
38     elif choice == 0:
39         print  "you buy goods is",shopping_car,
40         print "your balance is %d"%(salary)
41         exit()

 

简单的购物车小程序