Currently, a Python beginner looking for some help. I'm reading from a text file with 365 lines of integers. Each integer is representative of a day of the year. Like this, but for 365 lines:
1102
9236
10643
2376
6815
10394
3055
3750
4181
5452
10745
I need to go through the whole file and separate the 365 days into each of the 12 months and take the average of the numbers of each month. For instance, the first 31 lines are January, take the average, print it, then continue from there...
At this point I have written code that goes through the whole file and gives a total for the year and an average per day, but am stuck on splitting the file into the separate months and taking individual averages. What do I do to achieve this?
Here's my current code:
import math
def stepCounter ():
stepsFile = open("steps.txt", "r")
stepsFile.readline()
count = 0
for line in stepsFile:
steps = int(line)
count = count + steps
avg = count / 365
print(count, "steps taken this year!")
print("That's about", round(avg), "steps each day!")
stepsFile.close()
stepCounter()
I hope this question was clear enough. Thanks for any help!