Counting Sundays
First read the problem description.
import datetime
def count_sundays():
= 0
sundays = datetime.timedelta(days=1)
one_day = datetime.date(1901, 1, 1)
date while date <= datetime.date(2000, 12, 31):
if date.day == 1 and date.isoweekday() == 7:
+= 1
sundays += one_day
date return sundays
print(count_sundays())
171
Source code of the solution(s):