i am given a a text file with 8 lines, and on each line there is an IDnumber, name, section and grade seperated by whitespace. im supposed to return the average for the given section. i am brand new to python therefore am having a horrible time trying to figure it out. can someone please help?
my parameters are a random textfile, and a section number
def average_by_secion (textfile, section):
'''(io.TextIOWrapper, str) -> flt or NoneType
Just posting some general process:
read every line of file and check if the section matches the section you need.
there are lots of tutorial on how to read a file in python. Csv module could help you turn your lines into either lists or dictionaries
if the line has a matching section number you could add its grade to a collection list
section_grades_list = []once you have a list of grades to average it should be pretty easy from there
sum(section_grades_list) / len(section_grades_list)