#!/usr/bin/env python # -*- coding:utf-8 -*- # @FileName :renwu.py # @Time :2020/11/13 10:03 # @AuThor :shui goods = [
{'name':'电脑','price':1999},
{'name':'鼠标','price':10},
{'name':'游艇','price':20},
{'name':'美女','price':9998},
{'name':'航母','price':19998},
{'name':'坦克','price':29998},
]
mygoods =[] def main_1(x):
l=[] for i in enumerate(x,1): # print(i) l.append(i) return l def jiaru(): while True: for i in main_1(goods):
print(i)
print('*'*40)
b = (input('请输入你要购买的商品序号或按0退出:')) if b.isdigit(): if int(b) > 0 and int(b) <= len(goods) :
mygoods.append(goods[int(b) - 1])
print("加入购物车成功", goods[int(b) - 1])
print('*'*40) elif int(b) == 0:
print('欢迎下次光临') break else:
print('商品序号不匹配,或没有该商品') else:
print('请输入正确的序号') def jiesuan():
sum=0 for i in mygoods: for y in i.values(): if str(y).isdigit():
sum+=y if sum<=a1[0]:
c=a1[0]-sum
a1.pop()
a1.append(c)
mygoods.clear()
print('购买成功',f'你还有{c}钱')
gongneng() else:
c = sum-a1[0]
print('余额不足',f'你还差{c}元')
gouwuche() def gouwuche():
y = '1' for i in mygoods:
y = i if y=='1':
print('没有宝贝')
b=int(input('0-返回主页 请输入 :')) if b == 0:
gongneng() else:
print("输入错误")
gouwuche() else:
print('*'*20)
gouwuchexianshi(mygoods)
b = int(input('1-购买,2-移除某个购物车,0-返回主页 请输入 :')) if b == 0:
gongneng()
elif b == 1:
jiesuan() elif b == 2:
del_1() # print('暂不支持该功能') # gouwuche() def gongneng():
b=input('1-进入我的购物车,2-显示商品列表,3-充值,0-退出 请输入 :')
if b=='1': # print(mygoods) gouwuche() # gongneng() elif b=='2': # print("列表通过 age 升序排序: ") # sorted(goods, key=lambda i: i['price']) jiaru()
gongneng() elif b=='3':
print('你有',a1[0],'元')
chongzhi() elif b=='0':
print('退出') return else:
print('请输入正确的序号')
gongneng() def mian_99(): # import time # print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))) #查看当前时间 global a1
a1=[]
a1.append(int(input('请输入你的总资产:')))
print('欢迎来到商城:')
print('你有',a1[0],'元')
gongneng() def del_1():
print('你的购物车有如下产品')
print('*'*30) for m in main_1(mygoods):
print(m)
del_2=input('请输入你要删除产品序号或按0退出:') if del_2 >'0' and del_2<=str(len(mygoods)) : del mygoods[int(del_2)-1]
print('删除成功')
del_1() elif del_2 == '0':
gouwuche() else:
print('请输入正确的序号')
del_1() def chongzhi(): while True:
b=input('输入序号选择功能1-充值,0-退出:') if b=='1':
b = input('你要充多少,充多少送多少,0-退出 请输入:') if b.isdigit():
print('*'*30) if b=='0':
chongzhi() else:
a1.append(int(b)+int(b)+a1[0]) del a1[0]
print('充值成功!你现在有',a1[0],'元') elif b=='0': break gongneng() # print('暂不支持') def gouwuchexianshi(x):
list1=[]
list2=[]
a=b=c=d=0 for i in x: if i not in list2:
a=x.count(i)
list1.append(f'{i}*{a}')
list2.append(i) # print(list1) for i in list1:
print(i)