• 用python实现简单购物车功能


    all_asset = 0
    
    i1 = input("请输入总资产:")
    
    all_asset = int(i1)
    goods = [
        {'name':'电脑','price':1999},
        {'name':'鼠标','price':10},
        {'name':'油田','price':20},
        {'name':'美女','price':998}
    ]
    for i in goods:
        print(i['name'],i['price'])
    
    car_dict = {}
    while True:
        i2 = input('请选择商品(Y/结算):')
        if i2 =="y":
            break
        for item in goods:
            if item['name'] == i2:
                name = item['name']
                if name in car_dict.keys():
                    car_dict[name]['num'] = car_dict[name]['num'] + 1
                else:
                    car_dict[name] = {'num': 1,'single_price': item['price']}
        print(car_dict)
    print(car_dict)
    all_price = 0
    for v in car_dict.values():
        m = v['num']
        n = v['single_price']
        all_sum = m * n
        all_price = all_price + all_sum
    
    if all_price >all_asset:
        print('穷逼','总价:'+ str(all_price),'余额:'+ str(all_asset-all_price))
    else:
        print('土豪','总价:'+ str(all_price),'余额:'+ str(all_asset-all_price))
    

      

  • 相关阅读:
    rocketMQ配置事故
    微信网页授权问题记录
    记一次Spring配置事故
    文件转换
    Java对象空间分配流程
    mysql(六)索引的数据结构
    mysql(五)查询缓存
    mysql(四)log
    从项目中加载文件
    cookie
  • 原文地址:https://www.cnblogs.com/Erick-L/p/6376550.html
Copyright © 2020-2023  润新知