码迷,mamicode.com
首页 > 编程语言 > 详细

购物车程序(python3.x)

时间:2018-06-17 18:56:43      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:enumerate   while   lis   输入   span   程序   git   pre   balance   

程序要求:

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...")

 

 

 

购物车程序(python3.x)

标签:enumerate   while   lis   输入   span   程序   git   pre   balance   

原文地址:https://www.cnblogs.com/summer-future/p/9193350.html

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