# open a file for reading file_object = open("testscores.txt", "r") # read in all data as one long String alldata = file_object.read() # split data at line break # because we know that's how it was stored data_split = alldata.split("\n") # store username and password as variables name = data_split[0] # iterate through rest of list to extract grades total = 0 num_tests = 0 for grade in data_split: if grade.isnumeric(): total += int(grade) num_tests += 1 # calculate average avg = total/num_tests # print out print(name, "'s average test score is: ", avg, sep = "") # close the file myvar.close()