Python Program to Display Calendar

In this post, we will learn how to display a calendar using Python Programming language.

This program asks the user to enter the month and year, then it displays the calendar of that month using the calendar module.

So, without further ado, let’s begin this tutorial.

Python Program to Display Calendar

# Python Program to Display Calendar

# Importing calendar module
import calendar

# Asking for input
year = int(input("Enter the year: "))
month = int(input("Enter the month: "))

# Displaying output
print(calendar.month(year, month))

Output

Enter the year: 2022
Enter the month: 1
January 2022
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
31

How Does This Program Work ?

# Importing calendar module
import calendar

In this program, we have imported a prebuilt calendar named module which contains the built in function to perform date related tasks.

# Asking for input
year = int(input("Enter the year: "))
month = int(input("Enter the month: "))

Then, the user is asked to enter the year and month.

# Displaying output
print(calendar.month(year, month))

The built in function month() takes the month and year and displays the calendar for that part of the year.

Conclusion

I hope after going through this post, you understand how to display a calendar using Python Programming language.

If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to help you.

Also Read:

Leave a Comment

Your email address will not be published.