0
点赞
收藏
分享

微信扫一扫

2019体育数据收入

minute_5 2022-02-09 阅读 65
python
with open('2019sport.csv', 'r', encoding='utf-8') as data:
    ls1 = []
    while True:
        tentative = data.readline().strip().split(',')
        if '' in tentative:
            break
        else:
            ls1.append(tentative)
            # print(ls1)
    # print(ls1)
option = input()

try:
    if 0 < int(option) <= 100:
        option = int(option)
        print(f'Rank: {option}\nName: {ls1[option][1]}\nPay: {ls1[option][2]}\nSalary/Winnings: {ls1[option][3]}\n'
              f'Endorsements: {ls1[option][4]}\nSport: {ls1[option][5]}\nYear: {ls1[option][6]}')
    else:
        print('Wrong Input')
except Exception as e:
    option = option.lower()
    if option == 'salary':
        try:
            option2 = int(input())
            if option2 > 100:
                option2 = 100
            ls2 = sorted(ls1[1:], key=lambda x: float(x[3].replace('$', '').replace(' M', '')), reverse=True)
            # print(ls2)
            index_num = 0
            while index_num < option2:
                print(f'{ls2[index_num][0][1:]} {ls2[index_num][1]} {ls2[index_num][3]}')
                # print(*ls2[index_num][:3])
                index_num += 1
        except:
            print('Wrong Input')
    else:
        print('Wrong Input')
举报

相关推荐

0 条评论