Python Program to Display Calendar

By | October 3, 2021
Python Program to Display Calendar

Here in this article, we have provided a python source code that displays the calendar of the user entered date.

Prerequisite topics to create this program.

  • Python Input, Output
  • Python User-Defined Function
  • Python Built-functions
  • Python Modules

In Python, we have an in-built module known as calendar which can be used to print a proper calendar interface according to the user input.

Vamware

Steps:

  • Import the calendar module
  • ask the user to enter month and year.
  • Use the calendar.month () method to print the month calendar.

Code:

import calendar
year = int(input("Enter the Year e.g. 2011: "))
month = int(input("Enter the Month e.g. 12: "))

print(calendar.month(year,month))

Output 1:

Enter the Year e.g. 2011: 2020
Enter the Month e.g. 12: 1
January 2020
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

Output 2:

Enter the Year e.g. 2011: 2019
Enter the Month e.g. 12: 12
December 2019
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

People are also reading:

Leave a Reply

Your email address will not be published. Required fields are marked *