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

Python小程序之购物车

时间:2017-03-08 22:31:05      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:min   item   continue   color   小程序   hone   not   git   please   

 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小程序之购物车

标签:min   item   continue   color   小程序   hone   not   git   please   

原文地址:http://www.cnblogs.com/dachenzi/p/6523279.html

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