标签:
#!/usr/bin/env python
#_*_coding:utf-8_*_
from huansuan import chuli
from tongji import tongji
flag=True
shengyu=0
a={}
chongzhi = 0
while flag:
saraly=int(raw_input("充值:").strip())
if saraly>0:
chongzhi+=saraly
shengyu+=saraly
print "当前余额:%s" %shengyu
else:
print"充值金额应大于0"
continue
while shengyu>0:
operation = raw_input("是否继续操作y/n:")
if operation == "y":
shangpin = {"iphone": "6000", "MacAir": "15000", "tea": "50", "book": "30"}
for key in shangpin:
print "%s %s" % (key, shangpin[key])
gm = raw_input("选择购买商品:").strip()
cl = int(chuli(shengyu,gm))
if cl < shengyu and cl!=-1:
shengyu=cl
tongji(gm,a)
print "已购买商品:%s 剩余金额:%s" %(a,shengyu)
continue
elif cl==shengyu:
shengyu=cl
word = raw_input("余额不足,输入c请充值或输入q退出")
if word == "q":
print "购物车中的商品:%s 剩余金额:%s 总计充值金额:%s" % (a, shengyu,chongzhi)
saraly=0
flag = False
break
else:
break
else:
print "所选商品不在列表中"
continue
elif operation==‘n‘:
print "欢迎下次光临,您已购买商品:%s 剩余金额:%s" % (a, shengyu)
flag=False
break
else:
print "请重新输入"
continue
#_*_coding:utf-8_*_
shangpin = {"iphone": "6000", "MacAir": "15000", "tea": "50", "book": "30"}
def chuli(money,wp):
if wp in shangpin:
if int(money)>=int(shangpin[wp]):
money=int(money)-int(shangpin[wp])
return money
else:
return money
else:
return -1
#_*_coding:utf-8_*_
def tongji(wp,yi_gou):
if wp in yi_gou:
yi_gou[wp]+=1
else:
yi_gou[wp]=1
标签:
原文地址:http://www.cnblogs.com/wangqianlfxh/p/5569777.html