python实验报告内容实现购物车系统_Python实践--购物车功能简单实现_百 ...
python实验报告内容实现购物车系统_Python实践--购物车功
能简单实现
实验环境:
operating system: Centos 6.3
slinaPython version:Python 2.6.6
知识点:
Python 基本数据类型的常⽤操作
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# __author__ = "ht"
#⼿机信息存放在字典中{'⼿机品牌':{'⼿机型号':['单价','数量']}}
MobilPhone = {'Ipone':{'ipone5':[1200,10],'ipone5s':[1500,15],'ipone6':[3000,20],'ipone6s':[5000,30]},
'HuaWei':{'HuaWeiP6':[1000,20],'HuaWeiP7':[1200,25],'HuaWeiP8':[1800,28],'HuaWeiP9':[2900,50]},
'MI':{'MI1':[600,20],'MI1s':[800,25],'MI2':[1000,30],'MI2s':[1200,50]},
}
#⽤户信息存放字典{'⽤户ID':['⽤户名','账号余额']}
UserInfo = {'001':['ht001',8000],'002':['ht002',10000],}
#⽤户登录校验
UserName = raw_input("Please Input your username:")
UserId = ""
flag = 1
while flag :
for uid,user in UserInfo.items() :
if UserName == user[0] :
UserId = uid
if UserInfo.has_key(UserId) :
print "login success"
flag = 0
else :
UserName = raw_input(UserName +" " + "not exists ,Please Input your username again:")
#输出⼿机品牌信息,供⽤户选择
print "⼿机品牌:"
for kind in MobilPhone.keys() :
哪个牌子的移动电源好
print kind
ChoseBrand = raw_input("Please chose brands you want")
while True :
if MobilPhone.has_key(ChoseBrand) : #判断⽤户输⼊的品牌信息是否存在
for model,value (ChoseBrand).items() : #存在输出品牌下⾯的型号、单价、数量信息供⽤户选择print "⼿机型号:%s,⼿机单价:%s元/台,剩余数量:%s台"%(model,value[0],value[1])长得丑活的久长得帅老的快
ChoseModel = raw_input("Please chose model you want")
(ChoseBrand).has_key(ChoseModel) : #确认⽤户输⼊⼿机型号是否存在
BuyNum = int(raw_input("Please input the number you want to buy"))#⽤户输⼊购买数量
ExistNum = (ChoseBrand).get(ChoseModel)[1]) - BuyNum #确认剩余数量能满⾜需求
if (ExistNum <= 0) :
print "sorry not enough chose again"
else :建党100周年感言简短
PayMoney = (ChoseBrand).get(ChoseModel)[0]) * BuyNum #计算需要话费的钱ConfirmPayMoney = raw_input('you need pay {money} RMB,please confirm(Y/N)'.format(money=PayMoney)) if (ConfirmPayMoney == 'Y'):
ExistMoney = (UserId)[1]) - PayMoney #确认⽤户账户余额能满⾜购买需求
if ExistMoney >= 0 :
print "Pay success, Surplus %d RMB"%(ExistMoney)
break
else :
print "your count is not enough money,Please Recharge"
elif (ConfirmPayMoney == 'N') :
print "Sorry, you quit"
break
else :
print "Input error,Chose again"
else :
三十而已大结局是什么print "The model you chosed is not exist"
else :
今年10月1日是中华人民共和国成立多少周年
ChoseBrand = raw_input("The brands you chosed is not exist,Please chose again")

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。