Write a Python program to find the date of the first Monday of a given week


The program prompts the user to input the week of the year and the year in the format "YYYY" and "WW", respectively. It then initializes a variable first_mon to represent the first Monday of the year, which is always in the first week.

The program uses the datetime module to parse the input string into a datetime object with the specified year and week, and the first Monday of the year. It then prints the date of the first Monday of the input week and year.

Source Code

import datetime 
week = input("Enter the Week of the Year :")
year = input("Enter the Year :")
first_mon = '1'
date = datetime.datetime.strptime(year + week + first_mon, "%Y%W%w")
print(date.date())

Output

Enter the Week of the Year :39
Enter the Year :2022
2022-09-26

Example Programs