【发布时间】:2020-05-11 23:16:02
【问题描述】:
我正在尝试在 python 中打印二维矩阵。但是,我只能打印浮动测试分数,而不能打印与行和列标题对应的字符串。
我正在尝试打印这个:
学生姓名 ex1 ex2 ex3
迈克 78.0 89.0 89.0
莎拉 98.0 78.0 65.0
大卫 84.0 83.0 98.0
但只能得到浮点数,无法弄清楚如何 添加行和列标题。
这是我迄今为止所拥有的:
studentName = int(input("enter the number of student: "))
studentExam = int(input("how many exam scores: "))
names_students = []
# Initialize matrix
matrix = []
# For user input
for i in range(studentName): # A for loop for row entries
exam_student = []
names_students.append(input("enter name of students" + str(i+1) + ": "))
for j in range(studentExam): # A for loop for column entries
exam_student.append(float(input("enter exam " + str(j+1) + ": ")))
matrix.append(exam_student)
#for printing
for i in range(studentName):
for j in range(studentExam):
print(matrix [i][j], end=" ")
print()
【问题讨论】: