码迷,mamicode.com
首页 > 其他好文 > 详细

简单的购物车小程序

时间:2016-12-15 00:22:24      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:thinkpad   rod   其他   continue   this   购物   one   app   exit   

 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()

 

简单的购物车小程序

标签:thinkpad   rod   其他   continue   this   购物   one   app   exit   

原文地址:http://www.cnblogs.com/lixuesong/p/6181424.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!