I have a data file containing steps on each line representing each day out of the year and I want to add the appropriate amount of lines to each month.
#Initilize lists
listOfSteps = []
Jan = []
Feb = []
Mar = []
Apr = []
May = []
Jun = []
Jul = []
Aug = []
Sept = []
Oct = []
Nov = []
Dec = []
# Open file into program and insert data into list called listOfSteps
step_file = open('/Users/gregoryyelverton/Desktop/Data files/steps.txt', 'r')
for line in step_file:
line = line.rstrip('\n')
listOfSteps.append(line)
# Create list with all months inside
months = [Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sept, Oct, Nov, Dec]
# Iterate through list containing months and insert
# the days within those months
for month in months:
#print(month)
if month == [Jan] or [Mar] or [May] or [Jul] or [Aug] or [Oct] or [Dec]:
month.append(listOfSteps[:31])
del listOfSteps[:31]
print('31 days')
if month == [Apr] or [Jun] or [Sept] or [Nov]:
month.append(listOfSteps[:30])
del listOfSteps[:30]
print('30 days')
else:
month.append(listOfSteps[:28])
del listOfSteps[:28]
print('28 days')
The problem I am running into is that each month isn't sent through the appropriate if loop. So they alternate between having 31/30 days and never even checks if it is supposed to have 28 days.