首页 > 其他 > 详细

购物车小程序

时间:2017-01-04 19:55:58      阅读:242      评论:0      收藏:0      [点我收藏+]
 1 # -*- coding:utf-8 -*-
 2 # Author:JinYu
 3 
 4 cart_list = [
 5     ("Ipone",5800),
 6     ("Mac pro",12000),
 7     ("Witch",20000),
 8     ("Book",100),
 9     ("apple",10),
10 ]
11 shopping = []
12 
13 salary = input("输入金额--->>:")
14 if salary.isdigit():
15     salary = int(salary)
16     while True:
17         for index,item in enumerate(cart_list):
18             print(index,item)
19         shop_code = input("输入需要购买的商品Id--->:")
20         if shop_code.isdigit():
21             shop_code = int(shop_code)
22             if shop_code < len(cart_list) and shop_code>=0:
23                 p_item = cart_list[shop_code]
24                 if p_item[1] <= salary:
25                     shopping.append(p_item)
26                     salary -= p_item[1]
27                     print("你买到的商品是%s,余额 \033[31;1m%s\033[0m"%(p_item,salary))28                 else:
29                     print("你的余额不足,余额%s"%(salary))
30             else:
31                 print("你输入的商品Id不存在-->:%s"%(shop_code))
32         elif shop_code == q:
33             print("----shopping list----")
34             for p in shopping:
35                 print(p)
36             print("你的余额还剩余:%s"%(salary))
37             exit()
38 
39         else:
40             print("你输入的id不否和规范-->:%s"%(shop_code))
41 else:
42     print("你输入的金额不否和规范-->%s"%(salary))

 

购物车小程序

原文:http://www.cnblogs.com/Baylor-Chen/p/6249719.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!