创建一个包含30个0的一维数组,为students。
使用for循环将每个值替换为40到100之间的随机值。
数组中的值分别表示一名学生在某门课上的总课程点数。
评估遵循线性评估。
计算如下:
有多少学生通过了这门课?
有多少学生得到了5级?
平均成绩是多少?
这门课不及格的学生比例是多少?
使用以下的hist函数绘制学生点的直方图。
import matplotlib.pyplot as plt
import numpy as np
plt.style.use('_mpl-gallery')
# make data
np.random.seed(1)
x = 4 + np.random.normal(0, 1.5, 200)
# plot:
fig, ax = plt.subplots()
ax.hist(x, bins=8, linewidth=0.5, edgecolor="white")
ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
ylim=(0, 56), yticks=np.linspace(0, 56, 9))
plt.show()
import random
students=[random.uniform(40, 100) for i in range(40)] # 若分数为小数
students=[random.randint(40, 100) for i in range(40)] # 若分数为整数
如有帮助,点一下下采纳