1、输入10个学生5门课的成绩,分别用函数实现下列功能1计算每个学生的平均分;2计算没门课的平均法;3找出50个分数中最小的分数所对应的学生和课程;0 -.2x-( ) 4计算平均方差其中×为某一学生的平均分
时间: 2024-01-01 10:05:51 浏览: 57
1. 计算每个学生的平均分:
```python
def avg_score_student(scores):
avg_scores = []
for i in range(len(scores)):
avg_scores.append(sum(scores[i])/len(scores[i]))
return avg_scores
```
2. 计算每门课的平均分:
```python
def avg_score_course(scores):
avg_scores = []
for i in range(len(scores[0])):
sum_score = 0
for j in range(len(scores)):
sum_score += scores[j][i]
avg_scores.append(sum_score/len(scores))
return avg_scores
```
3. 找出所有50个分数中最高的分数所对应的学生和课程:
```python
def max_score(scores):
max_score = 0
max_student = 0
max_course = 0
for i in range(len(scores)):
for j in range(len(scores[i])):
if scores[i][j] > max_score:
max_score = scores[i][j]
max_student = i+1
max_course = j+1
return max_student, max_course
```
4. 计算平均分方差:
```python
def variance(scores, avg_scores):
var_scores = []
for i in range(len(scores)):
sum_var = 0
for j in range(len(scores[i])):
sum_var += (scores[i][j] - avg_scores[i])**2
var_scores.append(sum_var/len(scores[i]))
return var_scores
```
阅读全文