#Skip to menu

Counting Sundays

First read the problem description.
import datetime


def count_sundays():
    sundays = 0
    one_day = datetime.timedelta(days=1)
    date = datetime.date(1901, 1, 1)
    while date <= datetime.date(2000, 12, 31):
        if date.day == 1 and date.isoweekday() == 7:
            sundays += 1
        date += one_day
    return sundays


print(count_sundays())
171

Source code of the solution(s):