体育收入排行2012-2019(用列表)

def read_file():
    with open('2012-19sport.csv', 'r', encoding='utf-8') as data:
        # ls1 = data.readline().strip().split(',')
        data.readline()
        ls2 = []
        for line in data.readlines():
            ls2.append(line.strip().split(','))
        # print(ls1)
        # print(ls2)
        for i in range(len(ls2)):
            ls2[i][0] = ls2[i][0].replace('#', '')
        # print(ls2)
        # print(ls1 + ls2)
        return ls2


def fun1(year, ls):
    k = int(input())
    ls_one_year = []
    for element in ls:
        # print(element)
        if element[6] == str(year):
            ls_one_year.append(element)
    for element in ls_one_year[:k]:
        print(*element, sep=' | ')


def fun2(ls):
    year = int(input())
    ls_one_year = []
    for item in ls:
        if item[6] == str(year):
            ls_one_year.append(item)
    ls1 = sorted(list(set(item[5] for item in ls_one_year)))
    for element in ls1:
        print(f'{ls1.index(element) + 1}: {element}')

    ls_key = [i for i in range(1, len(ls1) + 1)]
    dt1 = dict(zip(ls_key, ls1))
    key = int(input())
    # print(dt1)
    ls_sport = []
    for element in ls_one_year:
        if element[5] == dt1[key]:
            ls_sport.append(element)
    # print(ls_sport)
    for element in ls_sport:
        print(*element, sep=' | ')

    ls_pay = []
    for element in ls_sport:
        ls_pay.append(float(element[2].replace('$', '').replace(' M', '')))
    # print(ls_pay)
    print('TOTAL: ${:.2f} M'.format(sum(ls_pay)))


if __name__ == '__main__':
    ls_return = read_file()
    option = input()
    try:
        option = int(option)
        if 2012 <= option <= 2019:
            fun1(option, ls_return)
        else:
            print('Wrong Input')
    except Exception as e:
        option = option.lower()
        if option == 'sport':
            fun2(ls_return)
        else:
            print('Wrong Input')

扫描下方二维码图片,关注后了解更多精彩内容!!

  • 6
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

二十四桥_

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

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

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

打赏作者

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

抵扣说明:

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

余额充值