利用合适的数据结构存储学生姓名,利用ndarry数组随机生成班上每个同学的三门成绩,比如Python、math、English。成绩范围为40~100,使用统计函数计算每门课程的成绩的最高分、最低分、平均分、标准差;打印班级三门课程总成绩的最高分、最低分的学生名字。从csv文件中读出本班学生名字数组.
时间: 2024-04-05 16:29:49 浏览: 60
import numpy as np
import pandas as pd
import statistics
import random
# 从CSV文件中读取学生姓名的数组
students = pd.read_csv('students.csv')
student_names = students['Name'].tolist()
# 使用ndarray数组随机生成班上每个同学的三门成绩
grades = np.random.randint(40, 101, size=(len(student_names), 3))
# 计算每门课程的最高分、最低分、平均分和标准差
python_scores = grades[:, 0]
math_scores = grades[:, 1]
english_scores = grades[:, 2]
python_max = np.max(python_scores)
python_min = np.min(python_scores)
python_mean = np.mean(python_scores)
python_std = statistics.stdev(python_scores)
math_max = np.max(math_scores)
math_min = np.min(math_scores)
math_mean = np.mean(math_scores)
math_std = statistics.stdev(math_scores)
english_max = np.max(english_scores)
english_min = np.min(english_scores)
english_mean = np.mean(english_scores)
english_std = statistics.stdev(english_scores)
# 打印班级三门课程总成绩的最高分、最低分的学生名字
total_scores = np.sum(grades, axis=1)
max_total_score_student = student_names[np.argmax(total_scores)]
min_total_score_student = student_names[np.argmin(total_scores)]
print('Python scores - max:', python_max, 'min:', python_min, 'mean:', python_mean, 'std:', python_std)
print('Math scores - max:', math_max, 'min:', math_min, 'mean:', math_mean, 'std:', math_std)
print('English scores - max:', english_max, 'min:', english_min, 'mean:', english_mean, 'std:', english_std)
print('Student with highest total score:', max_total_score_student)
print('Student with lowest total score:', min_total_score_student)
阅读全文