从键盘输入3个学生数据,要求输出3门课程总平均成绩,以及最高分的学生数据(包括学号、姓名、3门课程平均成绩、平均分数)
时间: 2023-04-07 19:01:15 浏览: 83
可以回答这个问题。以下是代码示例:
请依次输入3个学生的学号、姓名、3门课程成绩(用空格分隔):
```python
student1 = input().split()
student2 = input().split()
student3 = input().split()
```
计算3门课程总平均成绩:
```python
avg_score1 = (int(student1[2]) + int(student2[2]) + int(student3[2])) / 3
avg_score2 = (int(student1[3]) + int(student2[3]) + int(student3[3])) / 3
avg_score3 = (int(student1[4]) + int(student2[4]) + int(student3[4])) / 3
```
找出最高分的学生数据:
```python
max_score = max(int(student1[2]), int(student1[3]), int(student1[4]), int(student2[2]), int(student2[3]), int(student2[4]), int(student3[2]), int(student3[3]), int(student3[4]))
if max_score == int(student1[2]):
max_student = student1
elif max_score == int(student1[3]):
max_student = student1
elif max_score == int(student1[4]):
max_student = student1
elif max_score == int(student2[2]):
max_student = student2
elif max_score == int(student2[3]):
max_student = student2
elif max_score == int(student2[4]):
max_student = student2
elif max_score == int(student3[2]):
max_student = student3
elif max_score == int(student3[3]):
max_student = student3
else:
max_student = student3
```
输出结果:
```python
print("3门课程总平均成绩为:", (avg_score1 + avg_score2 + avg_score3) / 3)
print("最高分的学生数据为:学号:", max_student[0], "姓名:", max_student[1], "3门课程平均成绩:", (int(max_student[2]) + int(max_student[3]) + int(max_student[4])) / 3, "平均分数:", max_score)
```
阅读全文