首页 > 编程语言 > 详细

python 练习购物车小程序

时间:2016-12-03 18:47:22      阅读:309      评论:0      收藏:0      [点我收藏+]
 1 # -*- coding:utf-8 -*-
 2 shp = [
 3     [iphone,5000],
 4     [offee,35],
 5     [shoes,800]
 6 ]
 7 pric_list = []
 8 e = int(raw_input("请输入账户金额:"))
 9 while True:
10     for i,p in enumerate(shp):
11         print i,p[0],p[1]
12     enther = raw_input("请输入要购买的商品序号:").strip()
13     if enther.isdigit():
14         enther = int(enther)
15         #p_price = products[choice][1]
16         pric = shp[enther][1]
17         if pric <= e:
18             pric_list.append(shp[enther])
19             e -= pric
20             print "您购买的%s已添加到购物车,剩余金额%s" %(shp[enther][0],e)
21         else:
22             print "金额不足,请重新选择,剩余金额%s" % e
23     elif enther == quit:
24         print "购买的商品列表"
25         for k,v in enumerate(pric_list):
26             print k,v
27             print "剩余金额为%s" % e
28         print "-----欢迎再次光临------"
29         break

实现了输入金额后购买商品直到金额不足

python 练习购物车小程序

原文:http://www.cnblogs.com/guigujun/p/6129200.html

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