python绘制直方图(成绩可视化),turtle绘图

本文介绍了使用Python进行成绩可视化的方法,包括输入学生信息,绘制成绩直方图,以及利用turtle库绘制国旗动画。通过示例展示了如何计算平均分、最高分、最低分并用matplotlib展示成绩分布,同时展示了使用turtle库创建小人和国旗的图形艺术。
摘要由CSDN通过智能技术生成

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值