任务描述
代码
import csv
import json
sum = 0
temp = []
with open('./tcdata/num_list.csv') as f:
f_csv = csv.reader(f)
for row in f_csv:
sum +=int( row[0])
temp.append(int(row[0]))
temp.sort(reverse=True)
if len(temp)>10:
temp=temp[:10]
result = {
'Q1': 'Hello world',
'Q2': sum,
'Q3': temp
}
f = open('result.json','w',encoding='utf-8')
json.dump(result,f,indent=4,ensure_ascii=False)
运行结果
总结分析
题目其实不难,但是我却提交了四次才通过,前两次是因为代码有语法错误,可能是我pycharm用久了,刚用vim不习惯吧!第三次错误是忘记写判空条件了。ε=(´ο`*)))唉,看来自己的编码水平还有待提高啊!继续努力吧。