with open('tiobe.txt', 'r', encoding='utf-8') as f:
a = f.read().replace('Date.UTC', '').replace('name : ', '').replace(',data : ', ':').split('\n')
dic = {}
for i in a:
dic.update(eval(i))
PL_name = input().lower()
year = int(input())
sum, num = 0, 0
for i in dic:
if i.lower() == PL_name:
for i2 in dic[i]:
if year in i2[0]:
print(i2)
sum += i2[1]
num += 1
break
if num != 0:
print(f'{PL_name}语言{year}年的tiobe平均值是{sum / num:.2f}')
else:
print(f'没有查到{PL_name}语言{year}年的tiobe数据')
扫描下方二维码
,关注后了解更多精彩内容!!

本文通过读取'tiobe.txt'文件,使用Python处理数据,实现了用户输入特定语言名和年份后,查询并计算该语言当年的Tiobe平均值。如果找到数据则输出结果,否则提示未找到相应数据。
1185

被折叠的 条评论
为什么被折叠?



