编写一个函数 print,打印一个学生的成绩数组,该数组中有5个学生的数据,每个学生的数据包括 num(学号)、name(姓名)、score[3](3门课的成绩)。用主函数输人这些数据,用 print 函数输出这些数据。
时间: 2024-06-14 19:03:34 浏览: 16
以下是编写的函数print,可以打印一个学生的成绩数组,该数组中有5个学生的数据,每个学生的数据包括num(学号)、name(姓名)、score[3](3门课的成绩)。用主函数输入这些数据,用print函数输出这些数据。
```python
def print_student_score(students):
for student in students:
print("num:{}, name:{}, score:{}".format(student[0], student[1], student[2]))
```
其中,students是一个包含5个学生数据的列表,每个学生数据是一个包含num、name和score的元组。
以下是主函数的实现,用于输入学生数据并调用print_student_score函数输出学生数据。
```python
def main():
students = []
for i in range(5):
num = input("请输入第{}个学生的学号:".format(i+1))
name = input("请输入第{}个学生的姓名:".format(i+1))
score = []
for j in range(3):
score.append(int(input("请输入第{}个学生的第{}门课的成绩:".format(i+1, j+1))))
students.append((num, name, score))
print_student_score(students)
if __name__ == '__main__':
main()
```
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)