list_hao = []
gouwuche = []
dingdan = []
list = [
{‘ming’:‘手机’,‘price’:‘3000’,‘count’:100},
{‘ming’:‘电脑’,‘price’:‘6000’,‘count’:30},
{‘ming’:‘数据线’,‘price’:‘150’,‘count’:100}]
while True:
print(‘欢迎使用淘宝购物,亲选择你需要的功能:1、注册账号,2、登录账号,3、退出系统’)
user = int(input())
if user == 1:
print(‘注册账号’)
print(’’ * 80)
account = input(‘请输入账号:’)
for pwd in range(3):
passwd = input(‘请输入密码:’)
passwd1 = input(‘请再次确认密码:’)
if passwd == passwd1:
print(‘注册成功’)
list_hao = [account,passwd]
break
else:
if pwd < 2:
print(‘密码两次不一致,请重新输入’)
elif pwd == 2:
print(‘输入次数太多,请重新注册’)
elif user == 2:
count = 1
while count <= 3:
print(‘登录账号’)
print(’’ * 80)
a = input(‘请您输入账号:’)
b = input(‘请您输入密码:’)
if a == account and b == passwd:
print(‘登录成功’)
while True:
print(‘请选择你要进入的界面:1、购物车,2、订单,3、搜索商品,4、退出’)
xuan = input()
print(gouwuche)
if xuan == ‘1’:
print(‘购物车’)
print(’’ * 80)
if len(gouwuche) == 0:
print(‘购物车为空’)
else:
for dict in gouwuche:
for key in dict.keys():
if key == ‘ming’:
print(‘名称:’+ dict[‘ming’])
if key == ‘price’:
print(‘价格:’+ dict[‘price’])
if key == ‘count’:
print(‘数量:%d’%dict[‘count’])
if xuan == ‘2’:
print(‘订单’)
print(’’ * 80)
if len(dingdan) == 0:
print(‘订单为空’)
else:
for dict in dingdan:
for key in dict:
if key == ‘ming’:
print(‘名称:’+ dict[key])
if key == ‘price’:
print(‘单价:’+ dict[key])
if key == ‘zongjia’:
print(‘总价:%d’%(int(dict[‘price’]) * mai))
if key == ‘count’:
print(‘购买数量:%d’%dict[‘count’])
if xuan == ‘3’:
print(‘请输入你要搜索的商品:’)
shang = input()
for dict in list:
if dict[‘ming’] == shang:
print(‘名称:’+dict[‘ming’])
print(‘单价:’+dict[‘price’])
print(‘库存:%d’%dict[‘count’])
print(’*’ * 80)
print(‘添加购物车还是购买,1、添加购物车,2、购买’)
zidian = {}
shu = input()
if shu == ‘1’:
mai = int(input(‘请输入添加数量:’))
isExist = False
if len(gouwuche) != 0:
for dic in gouwuche:
if dic[‘ming’] == shang:
dic[‘count’] += mai
isExist = True
print(‘更新成功’)
break
if not isExist:
if mai <= dict[‘count’]:
zidian[‘ming’] = dict[‘ming’]
zidian[‘price’] = dict[‘price’]
zidian[‘count’] = mai
gouwuche.append(zidian)
print(‘添加成功’)