python学生成绩单---总分、平均成绩统计

知识点–数组、循环、jion函数、文件读写操作。

scores=[
    ["001","李明",92.5,93,94],
    ["002","李达",86,91,99],
    ["003","李硕",94.5,93,88],
    ["004","李东",86.5,81,87],
    ["005","李填",80.5,85,80],
    ["006","李乐",78,86,80],
    ["007","李中",79.5,77,76],
    ["008","李勤",95,88,92],
    ["009","李国",98,99,90],
    ["010","李开",988,94,98],
    ["011","李中",98.5,63,84],
    ["012","李祖名",90,92,90]
 ]
print(scores)
head=["学号","姓名","语文","数学","总分","平均分"]
with open("std.txt","w")   as fs:
    fs.write(",".join(head)+"\n")    #把head以逗号分隔的字符串,写入文件,如果列表内有数字,则写入失败
    for student in scores:
        total = 0
        for j in range(2,5):
            total +=student[j]
        student.append(total)
        student.append(int(total/3))
        #print(student)
        for y in student:
            fs.write(str(y)+" ")
        fs.write("\n ")

你可能感兴趣的:(python,python)