首页 > 编程语言 > 详细

python-购物车

时间:2019-01-06 17:18:46      阅读:169      评论:0      收藏:0      [点我收藏+]
 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-购物车

原文:https://www.cnblogs.com/wangxy629/p/10229129.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!