python练习题

1、有一个存着学生成绩的文件,里面存的是json串,json串读起来特别不直观,需要你写代码把它都写到excel中,并计算出总分和平均分,json格式如下

score={
"1":["小花",99,100,98.5],
"2":["小王",90,30.5,95],
"3":["小明",67.5,49.6,88]
}

import xlwt
score={
    "1":["小花",99,100,98.5],
    "2":["小王",90,30.5,95],
    "3":["小明",67.5,49.6,88]
}
title=['学号','姓名','语文成绩','数学成绩','英语成绩','总分','平均分']
book=xlwt.Workbook()
sheet=book.add_sheet('学生分数')
sheet2=book.add_sheet('1')
for col,title_name in enumerate(title):
    sheet.write(0,col,title_name)
row=1
for k,v in score.items():
    sheet.write(row,0,k)
    totle_score=sum(v[1:])
    sheet.write(row,5,totle_score)
    sheet.write(row,6,round(totle_score/3,2))
    for col,num in enumerate(v,1):
        sheet.write(row,col,num)
        col+=1
    row+=1
book.save('stu_score.xls')

2、额,来个小插曲,写程序求出1-100的累加和。1+2+3+4+5+.....+100。

posted @ 2019-07-16 09:59  4jd121de2gf4e2sa5d  阅读(314)  评论(0编辑  收藏  举报