Python: Check whether a given month and year contains a Monday 13th
Python Basic - 1: Exercise-130 with Solution
Write a Python program to check whether a given month and year contains a Monday 13th.
Sample Solution-1:
Python Code:
from datetime import date
def test(month, year):
return str(date(year,month,13).strftime("%A")=='Monday')
month = 11;
year = 2022;
print("Month No.: ", month, " Year: ", year);
print("Check whether the said month and year contains a Monday 13th.: " + test(month, year));
month = 6;
year = 2022;
print("\nMonth No.: ", month, " Year: ", year);
print("Check whether the said month and year contains a Monday 13th.: " + test(month, year));
Sample Output:
Month No.: 11 Year: 2022 Check whether the said month and year contains a Monday 13th.: False Month No.: 6 Year: 2022 Check whether the said month and year contains a Monday 13th.: True
Flowchart:

Sample Solution-2:
Python Code:
import calendar
def test(month, year):
return str(calendar.weekday(year, month, 13) == 0)
month = 11;
year = 2022;
print("Month No.: ", month, " Year: ", year);
print("Check whether the said month and year contains a Monday 13th.: " + test(month, year));
month = 6;
year = 2022;
print("\nMonth No.: ", month, " Year: ", year);
print("Check whether the said month and year contains a Monday 13th.: " + test(month, year));
Sample Output:
Month No.: 11 Year: 2022 Check whether the said month and year contains a Monday 13th.: False Month No.: 6 Year: 2022 Check whether the said month and year contains a Monday 13th.: True
Flowchart:

Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to get the index number of all lower case letters in a given string.
Next: Write a Python program to count number of zeros and ones in the binary representation of a given integer.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join