1.成绩可视化,输入成绩,绘制直方图
lis_score=[]
n=int(input("输入学生人数:"))
while n<1:
print("学生人数需大于1")
n = int(input("输入学生人数:"))
def check_score(score):
if score >= 0 and score <= 100:
return score
else:
print("分数未符合规范,请在1~100之间,确认后重新录入。!")
score = int(input("输入分数:"))
score = check_score(score)
j = 3
num_list=[]
b=[]
while j > 0 :
num = eval(input("输入学生学号(1,2,3,4...):"))
num_list.append(num)
i = n
a = []
while i > 0:
score = check_score(int(input("输入该学生分数:")))
a.append(score)
i -= 1
ave_score = (sum(a) / n)
lis_score.append([num,round(ave_score,2),max(a),min(a)])
j -= 1
print('最高分{:.2f}分,最低分{:.2f}分,平均分{:.2f}分'.format(max(a),min(a),ave_score))
print("总分{:.2f}分".format(sum(a)))
b.append(a)
print(lis_score)
print(b)
import csv
list=lis_score
f = open('成绩表.csv','w',newline='')
writer = csv.writer(f)
for i in list:
writer.writerow(i)
f.close()
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = ['SimHei']
plt.title("成绩分布柱状图")
for i in range(num):
x=[num_list[i]]
height=[lis_score[i][1]]
plt.bar(x,height)
plt.xlabel("学生学号——平均分")#设置x轴标签
plt.ylabel("成绩分数段")#设置y轴标签
plt.xlim(0,10)#设置x轴区间
plt.xticks(range(1,10))#设置x轴刻度
plt.yticks([0,10,20,30,40,50,60,70,80,90,100]) #设置y轴刻度
plt.grid()
plt.show()
for i