python读入成绩txt文件,统计各个分数段的人数

python读入成绩文件,统计各个分数段的人数

file=open("G:\\score.txt","r")
a=0
b=0
c=0
d=0
e=0
next(file)
for line in file.readlines():
    line=line.replace("\n",'')
    score=int(line[-2:])
    print(line)
    if score>=90:
        a=a+1
    elif score>=80:
        b=b+1
    elif score>=70:
        c=c+1
    elif score>=60:
        d=d+1
    else:
        e=e+1
print(" 90分以上:",a)
print("80到89分段:",b)
print("70到79分段:",c)
print("60到69分段:",d)
print(" 60分以下:",e)

'''
score.txt
可以自行复制粘贴创建文件
文件中的内容为:
学号	成绩
*101	85
*102	87
*103	96
*104	94
*106	93
*107	94
*108	91
*109	94
*110	92
*111	82
*113	93
*114	94
*115	92
*116	93
*117	94
*118	89
*119	94
*120	87
*121	87
*122	90
*124	96
*125	93
*126	97
*127	96
*128	91
*129	88
*131	87
*132	94
*133	94
*134	55
*135	90
*136	91
*137	92
*138	95
*139	84
*140	94
'''

猜你喜欢

转载自blog.csdn.net/tdl320721/article/details/109062270