Python三酷猫的钓鱼记录(最大鱼类,最大数量,总数量,总金额)

dir_date1 = {
    '三酷猫': {
        '鲫鱼': [17, 10.5],
        '鲤鱼': [8, 6.2],
        '鲢鱼': [7, 4.7]
    },
    '加菲猫': {
        '黑鱼': [8, 16]
    },
    '大脸猫': {
        '草鱼': [12, 8]
    }
}
dir_date2 = {
    '三酷猫': {
        '草鱼': [2, 7.2],
        '鲫鱼': [3, 12],
        '黑鱼': [6, 15]
    },
    '加菲猫': {
        '鲤鱼': [9, 7.1]
    }
}
dir_date3 = {
    '三酷猫': {
        '乌龟': [1, 78.10],
        '鲫鱼': [1, 10.78],
        '草鱼': [5, 7.92]
    },
    '大脸猫': {
        '鲫鱼': [8, 9.8],
        '螃蟹': [5, 15]
    }
}
fish_records = {
    '1月1日': dir_date1,
    '1月2日': dir_date2,
    '1月3日': dir_date3
}

# 钓鱼总数量
total_nums = 0
# 钓鱼总金额
total_amount = 0
# 三酷猫的统计结果
three_cool_cat_statistics = {}

for day, day_record in fish_records.items():
    # 三酷猫当天钓鱼数量
    day_nums = 0
    # 三酷猫当天钓鱼金额
    day_amount = 0
    # 三酷猫当天每种鱼的数量和金额
    daily_fish_statistics = {}

    if '三酷猫' in day_record:
        three_cool_cat_record = day_record['三酷猫']
        for fish, fish_record in three_cool_cat_record.items():
            # 统计每种鱼的数量和金额
            if fish in daily_fish_statistics:
                daily_fish_statistics[fish][0] += fish_record[0]
                daily_fish_statistics[fish][1] += fish_record[0] * fish_record[1]
            else:
                daily_fish_statistics[fish] = [fish_record[0], fish_record[0] * fish_record[1]]

            # 统计三酷猫当天钓鱼总数量和总金额
            day_nums += fish_record[0]
            day_amount += fish_record[0] * fish_record[1]

            # 统计三天总的钓鱼数量和金额
            total_nums += fish_record[0]
            total_amount += fish_record[0] * fish_record[1]

    # 保存三酷猫每天的统计结果
    three_cool_cat_statistics[day] = {'数量': day_nums, '金额': day_amount, '鱼类统计': daily_fish_statistics}

print('=========每日钓鱼记录==========')
for day, stats in three_cool_cat_statistics.items():
    # print(f'{day}钓鱼数量为{stats["数量"]}, 金额为{stats["金额"]}')
    # print('鱼类统计:')
    print(f'{day}钓鱼记录为:')
    for fish, fish_stats in stats['鱼类统计'].items():
        print(f'\t{fish}数量{fish_stats[0]},单价{fish_stats[1] / fish_stats[0]:.2f}元')

# 按鱼进行数量,金额统计
# 相同的鱼归为一类
# 合并每种鱼的统计结果
merged_fish_statistics = {}

for day, stats in three_cool_cat_statistics.items():
    for fish, fish_stats in stats['鱼类统计'].items():
        # 如果已经存在的鱼类只需要计算数量、金额
        if fish in merged_fish_statistics:
            # 计算每种鱼的总数量
            merged_fish_statistics[fish][0] += fish_stats[0]
            # 计算每种鱼的总金额
            merged_fish_statistics[fish][1] += fish_stats[1]
        # 不存在的鱼要添加
        else:
            merged_fish_statistics[fish] = [fish_stats[0], fish_stats[1]]

print('=====按鱼进行数量,金额统计=====')
for fish, fish_stats in merged_fish_statistics.items():
    print(f'{fish}的总数量{fish_stats[0]},金额为{fish_stats[1]:.2f}元')

# 最大值,总数量,总金额统计
print('====最大值,总数量,总金额统计====')
max_fish_nums = max(merged_fish_statistics, key=lambda x: merged_fish_statistics[x][0])
max_fish_money = max(merged_fish_statistics, key=lambda y: merged_fish_statistics[y][1])
print(f'最大数量的鱼是{max_fish_nums},{merged_fish_statistics[max_fish_nums][0]}条')
print(f'最大金额的鱼是{max_fish_money},{merged_fish_statistics[max_fish_money][1]}元')
print(f'钓鱼总数量为{total_nums},总金额为{total_amount:.2f}元')

输出结果:

=========每日钓鱼记录==========
1月1日钓鱼记录为:
    鲫鱼数量17,单价10.50元
    鲤鱼数量8,单价6.20元
    鲢鱼数量7,单价4.70元
1月2日钓鱼记录为:
    草鱼数量2,单价7.20元
    鲫鱼数量3,单价12.00元
    黑鱼数量6,单价15.00元
1月3日钓鱼记录为:
    乌龟数量1,单价78.10元
    鲫鱼数量1,单价10.78元
    草鱼数量5,单价7.92元
=====按鱼进行数量,金额统计=====
鲫鱼的总数量21,金额为225.28元
鲤鱼的总数量8,金额为49.60元
鲢鱼的总数量7,金额为32.90元
草鱼的总数量7,金额为54.00元
黑鱼的总数量6,金额为90.00元
乌龟的总数量1,金额为78.10元
====最大值,总数量,总金额统计====
最大数量的鱼是鲫鱼,21条
最大金额的鱼是鲫鱼,225.28元
钓鱼总数量为50,总金额为529.88元

转载出处:三酷猫管理复杂的钓鱼账本 | AIR (airusc.github.io)icon-default.png?t=N7T8https://airusc.github.io/2020/07/27/%E4%B8%89%E9%85%B7%E7%8C%AB%E7%AE%A1%E7%90%86%E5%A4%8D%E6%9D%82%E7%9A%84%E9%92%93%E9%B1%BC%E8%B4%A6%E6%9C%AC/

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

渣渣虎

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值