python-购物车

Posted wangxy629

tags:

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

 1 #购物车
 2 #商品信息
 3 product_list=[
 4     (mac,10000),
 5     (car,10000),
 6     (book,50),
 7     (shoes,200),
 8     (kindle,800),
 9     (food,10),
10 ]
11 shopping_car=[]
12 saving=input("please input your money:")
13 if saving.isdigit():
14     saving=int(saving)
15 else:
16     print("invalid input")
17 while True:
18     for i ,v in enumerate(product_list,1):
19         print(i,"<<<",v)
20     choice=input("please input the number of these "
21                      "goods which you want to buy(press q to eixt)")
22     if choice.isdigit():
23         choice=int(choice)
24         if choice>0 and choice < len(product_list):
25             p_iterm=product_list[choice-1]
26             if saving >=p_iterm[1]:
27                 saving-=p_iterm[1]
28                 shopping_car.append(p_iterm)
29             else:
30                 print("don‘t have ennough money")
31             print(p_iterm)
32         else:
33             print("the number is not exit")
34     elif choice==q:
35         print("---------you have buy somethings as follows------- ")
36         for i in shopping_car:
37             print(i)
38         print("the rest of money%s"%saving)
39         break
40     else:
41         print("invalid input")

 

以上是关于python-购物车的主要内容,如果未能解决你的问题,请参考以下文章

python 购物车代码

Python简单的购物车小代码

Python小代码_3_购物车

常用python日期日志获取内容循环的代码片段

python 有用的Python代码片段

Python 向 Postman 请求代码片段