The following links contain 2 csv files that the function should pass through grades_1e_2a grades_2e_4a
However my function is only able to pass the 2nd linked file, as it is hardcoded to range(4,8)
.
output: [91.5, 73.5, 81.5, 91.5]
The input file will start at the 4th element but may not necessarily end at the 8th element.
def class_avg(open_file):'''(file) -> list of floatReturn a list of assignment averages for the entire class given the openclass file. The returned list should contain assignment averages in theorder listed in the given file. For example, if there are 3 assignmentsper student, the returned list should 3 floats representing the 3 averages.'''marks=[[],[],[],[]]avgs = []for line in open_file:grades_list = line.strip().split(',')for idx,i in enumerate(range(4,8)):marks[idx].append(float(grades_list[i]))for mark in marks:avgs.append(float(sum(mark)/(len(mark))))return avgs
How do I fix this so that my code will be able to read both files, or any file? I have already opened the file and iterated past the first line with file.readline() in a previous function on the same file. Thanks for everyone's help in advance.
Updated progress: https://gyazo.com/064dd0d695e3a3e1b4259a25d1b0b1a0