Python Program to Display Calendar

Python Program to display calendar. Source code includes calling of calendar function, input of year, month and printing on the computer screen. This is for beginners, class 11,12 and B Tech computer science lab practical students. Download source code for free.

Python Program to display calendar

What is a calendar ?

A calendar is a system of organizing days. This is done by giving names to periods of time, typically days, weeks, months and years. A date is the designation of a single, specific day within such a system.

What is a month ?

A month is a unit of time, used with calendars, that is approximately as long as a natural orbital period of the Moon.

What is a year ?

A year or annum is the orbital period of a planetary body

Approach :

  • We will ask to input the calendar year.
  • We will ask to input the calendar month.
  • Then by the imported library calendar is called with month and year .
  • The result of the calendar year and month is shown.

Source code :

import calendar  
yy = int(input("Enter year: "))  
mm = int(input("Enter month: "))  
print(calendar.month(yy,mm)) 

Download Source code : For Download Click on the below Button

Step wise Source Code Explanation :

Step 1 : First import the calendar module
import calendar
Step 2 : ask of month and year
yy = int(input(“Enter year: “))
mm = int(input(“Enter month: “))
Step 3 : display the calendar
print(calendar.month(yy,mm))

Output :

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
 RESTART: C:/Users/ARCHIT/AppData/Local/Programs/Python/Python37-32/test1.py 
Enter year: 2001
Enter month: 5
      May 2001
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

>>> 
 RESTART: C:/Users/ARCHIT/AppData/Local/Programs/Python/Python37-32/test1.py 
Enter year: 2022
Enter month: 4
     April 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

>>> 

Output Explanation :

Year is captured.
Enter year: 2001
Month is captured.
Enter month: 5
Calendar is printed

  May 2001
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

Year is captured.
Enter year: 2022
Month is captured.
Enter month: 4
Calendar is printed

     April 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

>>> 

Conclusion :

The program is running fine.

Thank you for reading and learning from Pyhton Program to display calendar post. Source code includes calling of calendar function, input of year, month and printing on the computer screen. This is for beginners, class 11,12 and B Tech computer science lab practical students. For reading and learning more programs.
Python Programs Archives – CS Study
Computer Science with Python Practical Book Solutions Class 11 Term -2 – CS Study
Computer Science Practical file for class 12 Term-2 – CS Study

Leave a Comment

Your email address will not be published.