Python Program to Display Calendar

Posted in

Python Program to Display Calendar
vinaykhatri

Vinay Khatri
Last updated on December 24, 2024

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

    Prerequisite Python Program to Display Calendar

    • 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.

    Steps:

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

    Python 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 Comment on this Post

    0 Comments