Python小程序之购物车

Posted

tags:

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

 1 goods = [
 2     (IPhone,5888),
 3     (Mac Pro,12888),
 4     (iWatch,2888),
 5     (Bike,888),
 6     (Cofe,16),
 7     (Book,85)
 8 ]
 9 money = int(input("Please Input your Money:"))
10 buylist = []
11 while True:
12     print(商品列表.center(30,-))
13     for index,items in enumerate(goods):
14         name,price = items
15         print(index,name,price)
16     user_choice = input(Please input your choice:)
17     if user_choice.isdigit():
18         user_choice = int(user_choice)
19         if user_choice < len(goods) and user_choice >= 0:
20             if money > goods[user_choice][1]:
21                 money -= goods[user_choice][1]
22                 buylist.append((%s,%s) % (goods[user_choice][0],goods[user_choice][1]) )
23             else:
24                 choice = input(The money are not enough,Continue? )
25                 if choice == y:
26                     continue
27                 else:
28                     print(您的购物车有:)
29                     for info in buylist:
30                         print(info)
31                     exit(您的余额为: %s   % money)
32         else:
33             print(input Error, retry)
34             continue
35     elif user_choice == q:
36         if len(buylist) == 0:
37             exit(您未购买任何东西,您的余额还有:%s % money)
38         else:
39             print(您的购物车有:)
40             for info in buylist:
41                 print(info)
42             print(您的余额为: %s  % money)
43     else:
44         print(\033[31;1mInput Error,retry\033[0m)
45         continue

 

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

python学习笔记——贰之购物车小程序_服务端

python学习笔记——贰之购物车小程序_客户端

微信小程序之购物车的功能

python购物车小程序

python基础之作业1----购物车小练习

python路5__购物车小程序练习