购物车程序(python3.x)

Posted summer-future

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了购物车程序(python3.x)相关的知识,希望对你有一定的参考价值。

程序要求:

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 33[31;1m%s33[0m into your shopcar...,your balance is 33[31;1m%s33[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 33[31;1m%s33[0m"%salary)
33             exit()
34         else:
35             print("your input is false....,plese input agin...")

 

 

 

以上是关于购物车程序(python3.x)的主要内容,如果未能解决你的问题,请参考以下文章

购物商城小程序

如何从 recyclerview 片段传递到另一个 recyclerview 片段

python2x如何迁移代码到python3中

Python3.x:sys.argv[]的简介

Python3.x基础学习-异常报错处理

用户登陆程序(python3.x)