Question: The task 3a , please read my python code . Run the code , can't get the result . Please modify and give full explaination


The task 3a , please read my python code . Run the code , can't get the result . Please modify and give full explaination . Thanks in advance!
avage.py ents/4.6 Week 4 Prac def readFile(fileName): fid =open(fileName, 'r') marks =[] far line in fid line line.strip line =line.split(!!) for i in range(2, len(line)): line[i]=int(line[i]) marks.append(line) fid.close() Tetun marks table=open(filename, 'r') def grade (mark): mark>=85: return TRD lif mark>=75: Teturn 1D de mark>=65: elif mark>=55: TEGUI for col return NO def calculate(table): for row in range(len(table)): total=0 1 in range(2, len(table[row])): total += table[row][coll avg=total/3 g=grade (mark) table[row].append table[row].append(g) return table fileName=input('Enter the name of the marks file:') table[row]=[] prith open(fileName) as fid: for table in file.readlines: data = calculate table.stripo.split() table[row].append(data) table-calculate(table) printr The Result is) print(table[row]> Morgan 256780905 69 45 Mehran 34545742 65 78 87 Gavin 04587864 87 56 76 Shannon 44678646 65 76 65 Task 3a: Average marks and grade You will now write the function called calculate that accepts your entire table (names and student IDs included) and calculates the average mark for each student. The average marks should be appended back to the original table. Additionally, you will also determine the students grade (HD, D, C, P, N) and also append this to the original table. Hint: To make your task easier create a function (def grade(mark)) that accepts a single mark and returns the grade. E.g. grade(85) would return 'HD'. You can then use this function inside your calculate function. For example: Enter the name of the marks file: named Marks tict ff'Rishaad', '22223333', 25, 65, 48, 46 0, 'N'), ('Leslie', 23232323', 78, 54, 68, 66.66666666666667, 'C'], ['Haidar", 18493214, 55, 46, 39, 46.666666666666664, 'N). ["Sel', '50015542', 70, 81, 75, 75.33333333333333, 'D'), l'Istiaque", 1355034011, 100, 98, 90, 96.0, "HD'], ['Morgan', 25678890', 65, 89, 43, 65,66666666666667 'CT, I'Mehran', 34545742", 65, 78, 87, 76.66666666666667, 'D'), l'Gavin', '04587864', 87, 56, 76, 73.0, D, 'Shannon, 144678646\, 65, 76, 65, 68,66666666666667, namedmarks.txt Rishaad, 22223333,25,65,48 Leslie, 23232323, 78,54,68 Haidar.. 28493214.55.46.39 Sel,59815542,70,81,75 Istiague,35593491.189.98.90. Morgan, 25678890, 65, 89, 43 Mehcan. 34545742.65.7R. B7 Gavin, 04587864,87,56,76 Shannon, 44678646, 65, 76,65
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
