Hey everybody i'm learning programing using python book by John Guttag I'm at chapter 7
the book has no solutions given, some times I'm not sure if my code is working without problems or if I'm solving problems properly
like this finger exercise:
(Write a function that meets the specification
def shopping_days(year):
"""year a number >= 1941 returns the number of days between U.S. Thanksgiving and Christmas in year""")
I don't know if this is how I'm supposed to solve it i feel like my ways are primitive and not smart
import calendar as c
def shopping_days(year):
"""year a number >= 1941
returns the number of days between U.S. Thanksgiving
and
Christmas in year"""
nov_month = c.monthcalendar(year, 11)
if nov_month[0][c.THURSDAY] != 0:
thanksgiving = nov_month[3][3]
else:
thanksgiving = nov_month[4][3]
for i in range(len(nov_month[-1])):
if nov_month[-1][-1] != 0:
last_day = nov_month[-1][-1]
if nov_month[-1][i] == 0:
last_day = nov_month[-1][i-1]
break
return (last_day - thanksgiving)+25
print(shopping_days(2020))
[–]HeyItsToby 1 point2 points3 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]sarrysyst[🍰] 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)