Why is it not including the last list

Why is it not including the last list
Right now I am debugging, and. was able to get my program to do what I want, but I wanted to know why is it when I had my range from (1, 43) did it exclude the last list but when I did range(43) it gives me the whole thing. I want my program to iterate from 1 - 42 (42 is included) and add every time there is a length of 7. Why does the computer do that? Here are snippets of my code # This is inside main function days = {months[0]: 31, months[1]: 28, months[2]: 31, months[3]: 30, months[4]: 31, months[5]: 30, months[6]: 31, months[7]: 31, months[8]: 30, months[9]: 31, months[10]: 30, months[11]: 31} def incrementDays(days): numStore = [] dayList = [] weekList = [] for i in range(1, 43): # i += 1 if len(dayList) == 7: numStore.append(dayList) dayList = [] if i > dayDisplay: i = "" dayList.append(i) for i in range(0, len(numStore)): weeks = {"MON": numStore[i][0], "TUE": numStore[i][1], "WED": numStore[i][2], "THU": numStore[i][3], "FRI": numStore[i][4], "SAT": numStore[i][5], "SUN": numStore[i][6]} weekList.append(weeks) print(f"{numStore}\n") return weekList OUTPUT: [[1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14], [15, 16, 17, 18, 19, 20, 21], [22, 23, 24, 25, 26, 27, 28], [29, 30, 31, '', '', '', '']] CORRECT VERSION def incrementDays(days): numStore = [] dayList = [] weekList = [] for i in range(43): # i += 1 if len(dayList) == 7: numStore.append(dayList) dayList = [] if i > dayDisplay: i = "" dayList.append(i) for i in range(0, len(numStore)): weeks = {"MON": numStore[i][0], "TUE": numStore[i][1], "WED": numStore[i][2], "THU": numStore[i][3], "FRI": numStore[i][4], "SAT": numStore[i][5], "SUN": numStore[i][6]} weekList.append(weeks) print(f"{numStore}\n") return weekList OUTPUT: [[0, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13], [14, 15, 16, 17, 18, 19, 20], [21, 22, 23, 24, 25, 26, 27], [28, 29, 30, 31, '', '', ''], ['', '', '', '', '', '', '']] This is not the full code and it is just rewritten to show the context of my question. UPDATE After reading the comments below, I was able to figure out why it was not displaying the full 42 indexes I only changed the range stopping point def incrementDays(days): numStore = [] dayList = [] weekList = [] for i in range(1, 44): # i += 1 if len(dayList) == 7: numStore.append(dayList) dayList = [] if i > dayDisplay: i = "" dayList.append(i) for i in range(0, len(numStore)): weeks = {"MON": numStore[i][0], "TUE": numStore[i][1], "WED": numStore[i][2], "THU": numStore[i][3], "FRI": numStore[i][4], "SAT": numStore[i][5], "SUN": numStore[i][6]} weekList.append(weeks) print(f"{numStore}\n") return weekList OUTPUT: [[1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14], [15, 16, 17, 18, 19, 20, 21], [22, 23, 24, 25, 26, 27, 28], [29, 30, 31, '', '', '', ''], ['', '', '', '', '', '', '']] submitted by /u/TheEyebal [link] [comments]

Take Your Experience to the Next Level

New

Download our mobile app for a faster and better experience.

Comments

0
U

Join the discussion

Sign in to leave a comment

0:000:00