In this article, we will show you, How to write a Python program to display the monthly calendar with an example.
Python Calendar Example
This example will accept year and month as input variables and using those values we are going to display the monthly calendar
# import calendar module import calendar # ask of month and year year = int(input("Please Enter the year Number: ")) month = int(input("Please Enter the month Number: ")) # Displaying the Python calendar print(calendar.month(year, month))
First, we are importing the calendar library provided by the Python programming language. The group of function present in this library can help you to perform many operations on the calendar
Next, we are asking the users to enter Year and Month number using the following statements. To make sure that, they are entering the integer values we used the typecast here.
year = int(input("Please Enter the year Number: ")) month = int(input("Please Enter the month Number: "))
The following statement will display the monthly calendar (Here, February 2016)
From the above statement, you can observe that we calling the month function present in the calendar library and this function accepts two parameters (i.e., Year and Month).
Thank You for visiting Our Blog