Python Program to Display Calendar

Python program to display calendar; Through this tutorial, i will show you how to display calendar in python.

In this tutorial, i will write a python program that will display calendar of given month using calendar module. And as well as, write a python program to print all the months of given year.

Python Program to Display Calendar

  • Write a python program that will display calendar of given month using calendar module
  • Python program to print whole year calendar

Write a python program that will display calendar of given month using calendar module

# Python program to print Calendar using
# Python Calender module
import calendar
# take year from user
year = int(input("Enter Year: "))
# take month from user
month = int(input("Enter Month: "))
# printing Calendar
print(calendar.month(year, month))

Output

Enter Year:  2020
Enter Month:  04

     April 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

Python program to print whole year calendar

# Python program to print Calendar using
# Python Calender module
import calendar
# take year from user
year = int(input("Enter Year: "))
cal = calendar.TextCalendar(calendar.MONDAY)
# year: 2022, column width: 2, lines per week: 1 
# number of spaces between month columns: 1
# 3: no. of months per column.
print(cal.formatyear(year, 2, 1, 1, 3))

Output

Enter Year:  2020
                              2020

      January               February               March
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
       1  2  3  4  5                  1  2                     1
 6  7  8  9 10 11 12   3  4  5  6  7  8  9   2  3  4  5  6  7  8
13 14 15 16 17 18 19  10 11 12 13 14 15 16   9 10 11 12 13 14 15
20 21 22 23 24 25 26  17 18 19 20 21 22 23  16 17 18 19 20 21 22
27 28 29 30 31        24 25 26 27 28 29     23 24 25 26 27 28 29
                                            30 31

       April                  May                   June
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
       1  2  3  4  5               1  2  3   1  2  3  4  5  6  7
 6  7  8  9 10 11 12   4  5  6  7  8  9 10   8  9 10 11 12 13 14
13 14 15 16 17 18 19  11 12 13 14 15 16 17  15 16 17 18 19 20 21
20 21 22 23 24 25 26  18 19 20 21 22 23 24  22 23 24 25 26 27 28
27 28 29 30           25 26 27 28 29 30 31  29 30

        July                 August              September
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
       1  2  3  4  5                  1  2      1  2  3  4  5  6
 6  7  8  9 10 11 12   3  4  5  6  7  8  9   7  8  9 10 11 12 13
13 14 15 16 17 18 19  10 11 12 13 14 15 16  14 15 16 17 18 19 20
20 21 22 23 24 25 26  17 18 19 20 21 22 23  21 22 23 24 25 26 27
27 28 29 30 31        24 25 26 27 28 29 30  28 29 30
                      31

      October               November              December
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
          1  2  3  4                     1      1  2  3  4  5  6
 5  6  7  8  9 10 11   2  3  4  5  6  7  8   7  8  9 10 11 12 13
12 13 14 15 16 17 18   9 10 11 12 13 14 15  14 15 16 17 18 19 20
19 20 21 22 23 24 25  16 17 18 19 20 21 22  21 22 23 24 25 26 27
26 27 28 29 30 31     23 24 25 26 27 28 29  28 29 30 31
                      30

 

Recommended Python Tutorials

Be First to Comment

Leave a Reply

Your email address will not be published.