林夕的成长

博客园 首页 联系 订阅 管理

程序要求:

1.输入你的薪水

2.可以根据商品号选择商品

3.可以在每次购买后显示余额

 

 

 1 shopping_list=[]
 2 products_list=[
 3     ("Ipone6" ,4000 ),
 4     ("Mac pro",5000 ),
 5     ("python book",80),
 6     ("bike",1200),
 7     ("coffee",20),
 8     ("drink",10)
 9 ]
10 salary=input("input your salary:")
11 if salary.isdigit():
12     salary=int(salary)
13     while True:
14         for index,item in enumerate (products_list ):
15             print(index,item)
16         choose_num=input("plese your choose...:")
17         if choose_num.isdigit():
18             choose_num=int(choose_num )
19             if choose_num<len(products_list) and choose_num >=0:
20                 if salary>=products_list[choose_num][1]:
21                     shopping_list.append(products_list[choose_num])
22                     p=products_list[choose_num]
23                     salary-=products_list[choose_num][1]
24                     print("added \033[31;1m%s\033[0m into your shopcar...,your balance is \033[31;1m%s\033[0m" % (p,salary ))
25                 else:
26                     print("your salary can not afford it....")
27             else:
28                 print("now,your choose is false....")
29         elif choose_num=="q":
30             for bought_products in shopping_list :
31                 print (bought_products )
32             print("your balance is \033[31;1m%s\033[0m"%salary)
33             exit()
34         else:
35             print("your input is false....,plese input agin...")

 

 

 

posted on 2018-06-17 17:51  IT林夕  阅读(95)  评论(0编辑  收藏  举报