zoukankan      html  css  js  c++  java
  • 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)
  • 相关阅读:
    记账本程序三
    记账本程序二
    记账本程序一
    <<人月神话>>笔记1
    库存管理系统
    Java实现数据库
    第九周作业
    四则运算总结
    java异常处理
    第十周学习进度报告
  • 原文地址:https://www.cnblogs.com/Bruce-yin/p/6815566.html
Copyright © 2011-2022 走看看