#from array_list import Array2D from array import Array2D filename = 'data.txt' # Open the text file for reading. grade_file = open( filename, "r" ) # Extract the first two values; indicate the size of the array. num_students = int( grade_file.readline() ) num_exams = int( grade_file.readline() ) # Create the 2-D array to store the grades. exam_grades = Array2D( num_students, num_exams ) # print('n_students ', num_students, 'n_exams ', num_exams) # Extract the grades from the remaining lines. i = 0 for student in grade_file : # print(' i ', i) grades = student.split() for j in range( num_exams ): # print(' j ', j) exam_grades[i,j] = int( grades[j] ) i += 1 # Close the text file. grade_file.close() # Compute each student's average exam grade. print("Student Grade") for i in range( num_students ) : total = 0 for j in range( num_exams ) : total += exam_grades[i,j] exam_avg = total / num_exams print( "%2d: %6.2f" % (i+1, exam_avg) )