I've taken a look online to try and solve this problem and used solutions from other posts to build towards my solution, however from here, I don't get what to do next.
I basically want to grab the final 5 lines of the PastWinners text file and then get the average of those numbers. What I currently have gets the average of the entire document and also prints out the final line in the text file.
with open('PastWinners.txt') as f:
data = [float(line.rstrip()) for line in f]
first = f.readline() # Read the first line.
f.seek(-2, 2) # Jump to the second last byte.
while f.read(1) != b"\n": # Until EOL is found...
f.seek(-2, 1) # ...jump back the read byte plus one more.
last = f.readline() # Read last line.
biggest = min(data)
smallest = max(data)
print(sum(data)/len(data))
print(last)
Thanks for the help.