首页 > 代码库 > shopping_cart
shopping_cart
1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 print(‘欢迎土豪光临随心所欲旗舰店‘) 4 user_money = int(input(‘老板,请输入你拥有的总资产:‘)) 5 shopping_list = [] 6 shopping_car = {} 7 chose_list = [] 8 out = ‘谢谢惠顾小店‘ 9 goods = [ 10 {"name": "电脑", "price": 1999}, 11 {"name": "鼠标", "price": 10}, 12 {"name": "游艇", "price": 20}, 13 {"name": "美女", "price": 998}, 14 ] 15 # 向用户展示商品 16 for i in enumerate(goods): 17 shop_id = i[0] 18 shop_name = i[1].get(‘name‘) 19 shop_money = i[1].get(‘price‘) 20 print(‘商品id:‘, shop_id, ‘商品:‘, shop_name, ‘售价:‘, shop_money) 21 enterone = input(‘请问你需要选购么?y/n‘) 22 if enterone.lower() and enterone == ‘y‘: 23 print(‘请您输入你想要的商品id,选购完毕离开请输入Q/q‘) 24 while True: 25 choose = input(‘上帝的选择:‘) 26 #if int(choose) > 3: 27 # print(‘亲爱的上帝,您输入的数字不在商品列表中,请重新输入‘) 28 # continue 29 #else: 30 # pass 31 if choose.lower() and choose == ‘q‘: 32 break 33 elif int(choose) > int(len(goods)): 34 print(‘亲爱的上帝,您输入的数字不在商品列表中,请重新输入‘) 35 continue 36 else: 37 now_money = user_money 38 user_money = user_money - goods[int(choose)].get(‘price‘) 39 if now_money <= goods[int(choose)].get(‘price‘): 40 print(‘您的账号余额:‘,now_money,‘购买:‘,goods[int(choose)],‘还差:‘,user_money) 41 #print(‘加入购物车失败!‘) 42 print(""" 43 1 充值 44 2 删减购物车 45 """) 46 now_chose = input(‘请选择:1/2‘) 47 if int(now_chose) == 1: 48 recharge_money = int(input(‘请输入充值金额:‘)) 49 user_money = user_money + recharge_money 50 print(‘您的账号金额:‘,user_money) 51 elif int(now_chose) == 2: 52 for w in enumerate(chose_list): 53 print(w) 54 while True: 55 remove_list = input(‘请输入您想要删除的商品id:退出请输入Q/q‘) 56 now_list = int(len(chose_list)) 57 if remove_list.lower() and remove_list == ‘q‘: 58 print(‘已成功返回上一层:‘) 59 break 60 elif int(remove_list) < now_list: 61 g = None 62 e = chose_list[int(remove_list)] 63 for g in enumerate(goods): 64 if str(e) in g[1].get(‘name‘) : 65 user_money = now_money + g[1].get(‘price‘) 66 print(‘您现在的余额为:‘,user_money) 67 del chose_list[int(remove_list)] 68 print(chose_list) 69 else: 70 print(‘输入有误请重新输入‘) 71 72 else: 73 chose_list.append(goods[int(choose)].get(‘name‘)) 74 print(chose_list) 75 print(chose_list) 76 else: 77 print(‘请稍候....,现在系统为你自动结算,‘) 78 #pass 79 print(‘您的账号余额:‘, user_money) 80 print(‘您购买的商品:‘,chose_list)
shopping_cart
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。