【输出形式】标题名Id、Name、Score1、Score2、Score3、Score4、GPA用\t分隔; 一行中的数据也用\t分隔; 【输入/输出样例】红色部分代表输入的信息。 Please enter students number:5 Please input all student information: 101 s01 88 68 76 80 102 s02 78 80 88 69 103 s03 50 68 62 55 104 s04 90 99 92 95 105 s05 62 71 80 75 Id Name Score1 Score2 Score3 Score4 gpa 101 s01 88.00 68.00 76.00 80.00 11.20 102 s02 78.00 80.00 88.00 69.00 11.50 103 s03 50.00 68.00 62.00 55.00 3.00 104 s04 90.00 99.00 92.00 95.00 17.60 105 s05 62.00 71.00 80.00 75.00 8.80 The highest gpa is 17.60, Id is 104, name is s04.
时间: 2023-03-05 15:23:18 浏览: 21
student-score-manage.rar_Score!_c++管理系统
以下是使用 Python 语言实现上述功能的代码示例:
```
# 输入学生数量
student_num = int(input("Please enter students number: "))
# 初始化最高 GPA 信息
highest_gpa = 0
highest_gpa_id = 0
highest_gpa_name = ""
# 循环输入每个学生的信息
for i in range(student_num):
# 输入学生信息
student_info = input("Please input all student information: ").split()
student_id = student_info[0]
student_name = student_info[1]
student_scores = [float(score) for score in student_info[2:]]
# 计算学生 GPA
student_gpa = sum(student_scores) / len(student_scores)
# 更新最高 GPA 信息
if student_gpa > highest_gpa:
highest_gpa = student_gpa
highest_gpa_id = student_id
highest_gpa_name = student_name
# 输出学生信息
print(f"{student_id}\t{student_name}\t{'\t'.join(['{:.2f}'.format(score) for score in student_scores])}\t{student_gpa:.2f}")
# 输出最高 GPA 信息
print(f"The highest gpa is {highest_gpa:.2f}, Id is {highest_gpa_id}, name is {highest_gpa_name}.")
```
这段代码实现了输入学生数量、输入每个学生的信息、计算学生 GPA、输出学生信息、输出最高 GPA 信息的功能。
阅读全文