Why do i get this error? Correct and detailed answer will be Upvoted sid = data[0]IndexError: list index out of rangeIn [80]: runfile('C:/Users/hussein/Documents/Lab/Lab12_ex2_s134580.py',...



Why do i get this error?



Correct and detailed answer will be Upvoted


# open file to read grades<br>grades = open('grades.txt', 'r')<br>New to Spyder? Read our tutorial<br># open file to write average of each student<br>results = open('results. txt', 'w')<br># read and iterate over lines in grades.txt<br>for line in grades:<br># split space separated data<br>data = line.split()<br># get student id<br>sid = data[@]<br># get total marks<br>total_marks = float(data[1]) + float(data[2]) + float(data[3])<br>Help Variable Explorer Plots Files<br># calculate average marks<br>avg = total_marks/3<br>Console 1/A x<br># write student id and average to results file<br>results.write(
sid = data[0] IndexError: list index out of range In [80]: runfile('C:/Users/hussein/Documents/Lab/Lab12_ex2_s134580.py', wdir='C:/Users/hussein/Document Reloaded modules: jupyter_client.session, zmq.eventloop, zmq.eventloop.ioloop, tornado.platform, tornad tornado.gen, zmq.eventloop.zmqstream, jupyter_client.jsonutil, jupyter_client.adapter, spyder, spyder.p PIL.Image, PIL.ImageMode, PIL.TiffTags, PIL._binary, PIL. util, PIL. imaging, cffi, cffi.api, cffi.lock Traceback (most recent call last): File "C:\Users\hussein\Documents\lab\lab12 ex2 s134580.py", line 21, in sid = data[0] IndexError: list index out of range In [81]: Higtory "/>
Extracted text: # open file to read grades grades = open('grades.txt', 'r') New to Spyder? Read our tutorial # open file to write average of each student results = open('results. txt', 'w') # read and iterate over lines in grades.txt for line in grades: # split space separated data data = line.split() # get student id sid = data[@] # get total marks total_marks = float(data[1]) + float(data[2]) + float(data[3]) Help Variable Explorer Plots Files # calculate average marks avg = total_marks/3 Console 1/A x # write student id and average to results file results.write("%s: %.2f\n" %(sid, avg)) Reloaded modules: jupyter_client.session, zmq.eventloop, zmq.eventloop.ioloop, tornado.platform, tornad tornado.gen, zmq.eventloop.zmqstream, jupyter_client.jsonutil, jupyter_client.adapter, spyder, spyder.p PIL.Image, PIL.ImageMode, PIL.TiffTags, PIL._binary, PIL. util, PIL. imaging, cffi, cffi.api, cffi.lock Traceback (most recent call last): # close both files grades.close() results.close() File "C:\Users\hussein\Documents\lab\lab12_ex2_s134580.py", line 21, in sid = data[0] IndexError: list index out of range In [80]: runfile('C:/Users/hussein/Documents/Lab/Lab12_ex2_s134580.py', wdir='C:/Users/hussein/Document Reloaded modules: jupyter_client.session, zmq.eventloop, zmq.eventloop.ioloop, tornado.platform, tornad tornado.gen, zmq.eventloop.zmqstream, jupyter_client.jsonutil, jupyter_client.adapter, spyder, spyder.p PIL.Image, PIL.ImageMode, PIL.TiffTags, PIL._binary, PIL. util, PIL. imaging, cffi, cffi.api, cffi.lock Traceback (most recent call last): File "C:\Users\hussein\Documents\lab\lab12 ex2 s134580.py", line 21, in sid = data[0] IndexError: list index out of range In [81]: Higtory
Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here