shopping_cart

时间:2023-03-09 19:18:20
shopping_cart
 #!/usr/bin/env python
# -*- coding: utf-8 -*-
print('欢迎土豪光临随心所欲旗舰店')
user_money = int(input('老板,请输入你拥有的总资产:'))
shopping_list = []
shopping_car = {}
chose_list = []
out = '谢谢惠顾小店'
goods = [
{"name": "电脑", "price": 1999},
{"name": "鼠标", "price": 10},
{"name": "游艇", "price": 20},
{"name": "美女", "price": 998},
]
# 向用户展示商品
for i in enumerate(goods):
shop_id = i[0]
shop_name = i[1].get('name')
shop_money = i[1].get('price')
print('商品id:', shop_id, '商品:', shop_name, '售价:', shop_money)
enterone = input('请问你需要选购么?y/n')
if enterone.lower() and enterone == 'y':
print('请您输入你想要的商品id,选购完毕离开请输入Q/q')
while True:
choose = input('上帝的选择:')
#if int(choose) > 3:
# print('亲爱的上帝,您输入的数字不在商品列表中,请重新输入')
# continue
#else:
# pass
if choose.lower() and choose == 'q':
break
elif int(choose) > int(len(goods)):
print('亲爱的上帝,您输入的数字不在商品列表中,请重新输入')
continue
else:
now_money = user_money
user_money = user_money - goods[int(choose)].get('price')
if now_money <= goods[int(choose)].get('price'):
print('您的账号余额:',now_money,'购买:',goods[int(choose)],'还差:',user_money)
#print('加入购物车失败!')
print("""
1 充值
2 删减购物车
""")
now_chose = input('请选择:1/2')
if int(now_chose) == 1:
recharge_money = int(input('请输入充值金额:'))
user_money = user_money + recharge_money
print('您的账号金额:',user_money)
elif int(now_chose) == 2:
for w in enumerate(chose_list):
print(w)
while True:
remove_list = input('请输入您想要删除的商品id:退出请输入Q/q')
now_list = int(len(chose_list))
if remove_list.lower() and remove_list == 'q':
print('已成功返回上一层:')
break
elif int(remove_list) < now_list:
g = None
e = chose_list[int(remove_list)]
for g in enumerate(goods):
if str(e) in g[1].get('name') :
user_money = now_money + g[1].get('price')
print('您现在的余额为:',user_money)
del chose_list[int(remove_list)]
print(chose_list)
else:
print('输入有误请重新输入') else:
chose_list.append(goods[int(choose)].get('name'))
print(chose_list)
print(chose_list)
else:
print('请稍候....,现在系统为你自动结算,')
#pass
print('您的账号余额:', user_money)
print('您购买的商品:',chose_list)