【发布时间】:2016-09-26 09:35:53
【问题描述】:
我有三个函数,一个用于计算实验室平均值,一个用于加权分数,一个用于程序平均值。这些函数计算用户选择的特定学生的分数。 (例如。将计算实验室平均值。仅适用于 Ablao 而不是其他学生)
Ablao 3 74 96 72 88 71 80 83 77 90 88 95 71 76 94 80 74 98 77
Anderson 3 76 92 98 95 92 76 93 97 85 76 85 93 82 88 75 84 92 77
Aspinwall 1 86 74 78 97 86 94 73 95 74 91 75 94 83 99 83 78 88 96
Bacon 4 72 95 81 80 89 88 100 87 87 81 79 77 75 83 87 96 72 95
文件中有 60 名学生的信息。姓名后的第一个数字代表学生的年级。 1=大一2=大二等
我需要创建一个新函数,该函数将使用我现有的函数来计算所有学生的平均数,以及每个年级学生的平均数,然后平均这些平均数,找到最大值和最小值。
到目前为止,我为此功能编写的代码不起作用,我不知道如何着手解决这个问题。
with open(FileName, 'r') as f:
line = f.readlines()
student_status=(float(line.split()[1]))
def make_lists_of_status():
if (student_status==1):
Freshman.append(student_scores)
elif (student_status==2):
Sophomores.append(student_scores)
elif (student_status==3):
Juniors.append(student_scores)
elif (student_status==4):
Seniors.append(student_scores)
预期的输出应该是这样的
This option is for viewing statistics sorted by the year of student.
Please select one of the following options:
a for ALL YEARS
b for FRESHMAN
c for SOPHMORES
d for JUNIORS
e for SENIORS
Enter your choice here: e
For Seniors:
High/Low/Mean of all Weighted Scores: 89.53999999999999 / 81.60000000000001 / 86.15736842105264
High/Low/Mean of all Lab Averages: 89.6 / 80.2 / 86.21052631578948
High/Low/Mean of all Program Averages: 94.33333333333333 / 77.0 / 86.78947368421052
【问题讨论】:
-
你能告诉我们你的其他三个函数的代码吗?你的意思是要计算所有学生成绩的平均值?
-
@MoonCheezes 这些函数一次只为一个学生工作,他们应该这样做,但我需要一个新函数来计算所有学生并按年级对分数进行排序
标签: python list function append