Python ProgrammingPython Programming

Print all Monday's of a specific year

##
# Python's program to print all Monday's of a specific year

from datetime import date, timedelta

year = 2018
date_object = date(year, 1, 1)
date_object += timedelta(days=1-date_object.isoweekday())

while date_object.year == year:
    print(date_object)
    date_object += timedelta(days=7)

Sample output of above program.
C:\programs\time>pep8 --first example13.py

C:\programs\time>python example13.py
2018-01-01
2018-01-08
2018-01-15
2018-01-22
2018-01-29
2018-02-05
2018-02-12
2018-02-19
2018-02-26
2018-03-05
2018-03-12
2018-03-19
2018-03-26
2018-04-02
2018-04-09
2018-04-16
2018-04-23
2018-04-30
2018-05-07
2018-05-14
2018-05-21
2018-05-28
2018-06-04
2018-06-11
2018-06-18
2018-06-25
2018-07-02
2018-07-09
2018-07-16
2018-07-23
2018-07-30
2018-08-06
2018-08-13
2018-08-20
2018-08-27
2018-09-03
2018-09-10
2018-09-17
2018-09-24
2018-10-01
2018-10-08
2018-10-15
2018-10-22
2018-10-29
2018-11-05
2018-11-12
2018-11-19
2018-11-26
2018-12-03
2018-12-10
2018-12-17
2018-12-24
2018-12-31

C:\programs\time>