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

老男孩购物车程序

时间:2017-04-26 14:43:37      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:break   log   int   ping   bre   color   编号   code   pen   

 1 salary = input(您的工资是:)
 2 item_list = [
 3     (iphone,5800),
 4     (pc,12325),
 5     (watch,7000),
 6     (book,38),
 7     (pen,5),
 8     (game,1000)
 9 ]
10 buy_list=[]
11 print(type(salary))
12 while True:
13     if salary.isdigit():
14         salary = int(salary)
15         break
16     else:
17         salary = input(请输入正确的工资,您的工资是:)
18 
19 while True:
20     # print(salary)
21 
22         # print(type(salary))
23         # print(salary)
24         for index, item in enumerate(item_list):
25             print(index, item)
26         user_choice = input(要买什么>>>:)
27         if user_choice.isdigit():
28             user_choice = int(user_choice)
29             if user_choice < len(item_list) and user_choice >= 0:
30                 p_item = item_list[user_choice]
31                 if salary >= p_item[1]:
32                     salary -= p_item[1]
33                     buy_list.append(p_item)
34                     print(余额:,salary)
35                 else:
36                     print(没钱了)
37             else:
38                 print(输入正确产品编号:)
39         elif user_choice == q:
40             print(-------------shopping list--------------)
41             for i in buy_list:
42                 print(i)
43             print(还剩下:,salary)
44             exit()
45         else:
46             print("输入正确商品")

 

老男孩购物车程序

标签:break   log   int   ping   bre   color   编号   code   pen   

原文地址:http://www.cnblogs.com/yl-2016/p/6768216.html

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