Python Exercise: Print the calendar of a given month and year


(Python Example for Citizen Data Scientist & Business Analyst)


Write a Python program to print the calendar of a given month and year.

Note: Use ‘calendar’ module.

Python calendar.month(theyear, themonth, w=0, l=0):

The function returns a month’s calendar in a multi-line string using the formatmonth() of the TextCalendar class.

‘l’ specifies the number of lines that each week will use.

Sample Solution:-

Python Code:

import calendar
y = int(input("Input the year : "))
m = int(input("Input the month : "))
print(calendar.month(y, m))

Sample Output:

Input the year : 2017                                                                                         
Input the month : 04                                                                                          
     April 2017                                                                                               
Mo Tu We Th Fr Sa Su                                                                                          
                1  2                                                                                          
 3  4  5  6  7  8  9                                                                                          
10 11 12 13 14 15 16                                                                                          
17 18 19 20 21 22 23                                                                                          
24 25 26 27 28 29 30


Write a Python program to print the calendar of a given month and year


Sign up to get end-to-end “Learn By Coding” example.



Applied Machine Learning & Data Science with Python, R and SQL.

A list of Python, R and MATLAB Codes for Applied Machine Learning and Data Science


Subscribe to our YouTube channel and press the ring to get latest update on Python and R coding recipesCoding is our strength.


Learn by Coding Categories:


Data Analytics:

Data Science:

Data Visualisation:

Machine Learning Recipe:




Supervised Learning:

Tabular Data Analytics:

End-to-End Data Science Recipes:

Applied Statistics:

Bagging Ensemble:

Boosting Ensemble:



Data Analytics:

Data Science:

Data Visualisation:

Decision Tree:


Machine Learning Recipe:

Multi-Class Classification:

Neural Networks:

Python Machine Learning:

Python Machine Learning Crash Course:

R Classification:

R for Beginners:

R for Business Analytics:

R for Data Science:

R for Data Visualisation:

R for Excel Users:

R Machine Learning:

R Machine Learning Crash Course:

R Regression:



Excel examples for beginners:

C Programming tutorials & examples:

Javascript tutorials & examples:

Python tutorials & examples:

R tutorials & examples:

SQL tutorials & examples:

SQL for Beginners in 2 Weeks:


Portfolio Projects for Aspiring Data Scientists: Tabular Text & Image Data Analytics as well as Time Series Forecasting in Python & R @



Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.