淘淘购物系统 (Python)

#首页
def tao_first():
t1 = '欢迎进入淘淘购物'.center(110)
print(t1)
print('~' * 130)
t2 = '注册'.center(20)
print(t2,end='\t')
t3 = '登陆'.center(65)
print(t3,end='\t')
t4 = '退出'.center(45)
print(t4,end='\t')
print()
print('~' * 130) #
#购物车首页
def tao_second():
second0 = '|| 购物车 ||'.center(125)
print(second0)
print()
print('=' * 130)
print('商品名称',end='\t')
print('价格',end='\t')
print('数量',end='\t')
print('\n')
for i in sprice:
print(i)
print('-' * 130)
print('提交订单'.center(20),end='\t')
print('删除订单'.center(65),end='\t')
print('添加订单'.center(45),end='\t')
print('\n')
print('查看订单'.center(20),end='\t')
print('继续购物'.center(65),end='\t')
print('退出系统'.center(45),end='\t')
print('\n')
print('=' * 130)

#登陆
shop_name = ''
def login():
l0 = '|| 登陆 ||'.center(115)
print(l0)
i = 3
while i > 0:
username = input('please input the username :')
password = input('please input the password : ')
if username in lisl[0::2] and password in lisl[1::2] :
wage.append(username)
wage.append(0)
shop_name = username
break
else:
i -= 1
print('验证失败,请再次尝试,您还有'+str(i)+'次机会')
continue
#注册
def enter():
while 1:
e0 = '|| 注册 ||'.center(115)
print(e0)
e1 = input('请输入用户名:')
e2 = input('请输入密码:')
e3 = input('请再次确认密码:')
if e3 == e2 and e1 not in lisl:
print('恭喜你注册成功,快去登陆吧...')
lisl.append(e1)
lisl.append(e3)
break
if e3 != e2 :
print('对不起你输入的密码两次不一致,请重新注册')
continue
if e1 in lisl:
print('对不起你输入的账户信息已存在,请重新注册')
continue
#工资
def staff_wage():
"""
wage = [uername : wage]
shop_name = uername
:return:
"""
while 1:
if wage[1] < money:
print(wage[0] + '的工资是' + str(wage[1]) + '人民币,不足以支付订单...')
print('|| 支付 ||'.center(115))
print('=' * 130)
print('充值金钱'.center(20),end='\t')
print('查看余额'.center(65),end='\t')
print('放弃支付'.center(45),end='\t')
print('\n')
print('=' * 130)
shop_k = input('请输入你要选择的功能<<<')
if shop_k == '充值金钱':
age = input('请输入你要充值的金钱<<<')
wage[1] = wage[1] + int(age)
print('恭喜你,充值成功!')
if shop_k == '查看余额':
print(wage[0] + '的余额是' + str(wage[1]) + '人民币')
if shop_k == '放弃支付':
break
if wage[1] > money :
wage[1] = wage[1] - money
print('订单提交成功!'+wage[0]+',您的余额还有'+str(wage[1])+'人民币')
sprice.clear()
break

#列表信息
lisl = ['deng','123','taibai','123456','alex','2019','Jing','2017']
sprice = []
#遍历商品
mess = [] # 列表,存上一级菜单
def message():
# 商品信息
shopping = {
'首页': {'天猫新品': {
'marmot保暖鹅绒':2219,
'丝飘本色卷纸':9,
'marmot男士长袖':229
}, '今日爆款': {
'拉菲珍藏波尔多6支':359,
'美心流心奶黄月饼礼盒':348,
'乳酸菌饮品340ml*12瓶整箱':16
}, '天猫超市': {
'蓝月亮洁净洗衣液':9,
'好想你免洗灰枣':9,
'友臣福建特产肉松饼':29
}, '飞猪旅行': {
'哈尔滨接机服务':30,
'芽庄泥浆浴一日游':58,
'张家界大峡谷门票':208
}
},

'母婴': {'毛绒玩具': {
'冰丝抱枕北极熊':268,
'猫咪陪你睡觉抱枕':69,
'可爱仓鼠小老鼠睡觉抱枕':29
}, '儿童运动鞋': {
'NIKE':1000,
'Adidas':800,
'乔丹':100
}, '益智玩具': {
'魔方':30,
'变形金刚':200,
'探索者':30000
}
},

'百货': {'低价清仓': {
}, '水杯': {
'马克杯':18,
'玻璃杯':5,
'保温杯':60
}, '拖鞋': {
'夏季拖鞋':20,
'冬季拖鞋':50
}, '颈枕': {
'u型枕':79,
'记忆枕':245
}
},

'运动': {'跑鞋': {
'NIKE': 1000,
'Adidas': 800,
'乔丹': 100
}, '自行车': {
'凤凰自行车':700,
'上海永久':500
}, '球鞋': {
'NIKE': 1000,
'Adidas': 800,
'乔丹': 100
}
}

}
while 1 :
print('商品信息'.center(110))
print('~' * 130)
for i in shopping:
print(i.center(110))
print('~' * 130)
choice = input('请输入你要访问的商品')
if choice in shopping:
if type(shopping[choice]) is int :
print('是否购买该商品,如果购买输入Y,否则输入b返回上一级菜单')
pp1 = input('<<<')
if pp1.upper() == 'Y':
for tom in range(len(sprice)):
if choice in sprice[tom][0]:
sprice[tom][2] = sprice[tom][2] + 1
break
# 每一次的信息变成列表形式
space = []
space.append(choice)
space.append(shopping[choice])
space.append(1)
sprice.append(space)
print('购买成功,已添加购物车!')
while len(sprice) > 1 :
if sprice[-1][0] in sprice[0:-1][0]:
del sprice[-1]
else:
break
else:
mess.append(shopping)
shopping = shopping[choice]
if choice == 'e':
break
if choice == 'b':
shopping = mess[-1]
del mess[-1]

#main0方法 #购物模块
def main0 ():
while 1:
tao_first()
t5 = input('你输入你要选择的功能<<<')
if t5 == '注册':
enter()
elif t5 == '登陆':
login()
break
elif t5 == '退出':
exit()
message()

money = 0 # 金钱【账单总值】
wage = [] #工资
#main1方法
def main1():
global money
while 1:
tao_second()
ma1 = input('你选择服务<<<')
if ma1== '提交订单':
for i in range(len(sprice)):
money = sprice[i][1] * sprice[i][2]
second2 = '|| 购物车订单 ||'.center(125)
print(second2)
print()
print('=' * 130)
print('商品名称', end='\t')
print('价格', end='\t')
print('数量', end='\t')
print('\n')
for i in sprice:
print(i)
print('-' * 130)
print('您本次需要支付'+str(money)+'人民币') staff_wage()

if ma1 == '删除订单': add_mal2 =
input('请输入你要删除的商品名称:') add_mal3 =
input('请输入你要删除该商品名称的个数:')
for tom in range(len(sprice)):
if add_mal2 in sprice[tom][0]:
if int(add_mal3) >= sprice[tom][2] :
del sprice[tom]
else: sprice[tom][
2] = sprice[tom][2] - int(add_mal3)
if ma1 == '添加订单': add_mal0 =
input('请输入你要添加的商品名称:') add_mal1 =
input('请输入你要添加该商品名称的个数:')
for tom in range(len(sprice)):
if add_mal0 in sprice[tom][0]: sprice[tom][
2] = sprice[tom][2] + int(add_mal1)
print('订单添加成功!')
if ma1 == '查看订单': second1 =
'|| 购物车订单 ||'.center(125)
print(second1)
print()
print('=' * 130)
print('商品名称', end='\t')
print('价格', end='\t')
print('数量', end='\t')
print('\n')
for i in sprice:
print(i)
print('-' * 130)
if ma1 == '继续购物': message()

if ma1 == '退出系统':
exit()


#main方法
def main(): main0() main1()main()





    原文作者:如果可以,我选择忘记
    原文地址: https://www.cnblogs.com/if-it-is-possible/p/11480691.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞