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

“购物车”练习

时间:2018-06-28 13:55:03      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:class   end   cart   list   out   long   while   sdi   购物   

Emm....

It‘s a shopping cart;

1.You need input your salary;

2.Output a products list,each product mast contain a sequence number;

3.You need input thr sequence number what you want to buy,if you input "q" print your shopping  list and your saving(salary);

4;Your salary must enough to add product to your shopping list,if not ...

 

Here is my code:

 1 salary =  input("input Your salary:")
 2 product = [
 3     (iphone,6000),
 4     (Mac Pro,14000),
 5     (mouse,100),
 6     (keyboar,300),
 7     (XiaoMi 2s,3000),
 8 ]
 9 p_list = []
10 while salary.isdigit():
11     salary=int(salary)
12     while True:
13         for index, item in enumerate(product):
14             print(index, item)
15         user_choose = input("input the num of product what You want wo buy:")
16         if user_choose.isdigit():
17             user_choose = int(user_choose)
18             if user_choose >= 0 and user_choose < len(product):
19                 if salary >= product[user_choose][1]:
20                     p_list.append(product[user_choose])
21                     salary -= product[user_choose][1]
22                     print("\033[1;42m The product added in Your shopping list \033[0m!")
23                 else:
24                     print("\033[1;41m Your salary is not enough;have try other product \033[0m!")
25             else:
26                 print("\033[1;41m Your inputted out of list \033[0m!")
27         elif user_choose == "q":
28             print("Your shoppong list:%s,Your salary is %s" % (p_list, salary))
29             exit()
30         else:
31             print("\033 [1;41m Your invalid option;choose again \033[0m!")
32 else:
33     print("输入错误")

it takes me all night long...  so stupid... hah..

“购物车”练习

标签:class   end   cart   list   out   long   while   sdi   购物   

原文地址:https://www.cnblogs.com/jipyu/p/9238096.html

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