codescracker


python

Python Program to Display Calendar



« Previous Program Next Program »


Display Calendar in Python

To display calendar in python, you have to ask from user to enter year and month to print the calendar of that year and month as shown here in the program given below.

Python Programming Code to Display Calendar

Following python program ask from user to enter year and month to display calendar:

# Python Program - Display Calendar

import calendar
print("------Calendar Program in Python------\n");
print("Enter 'x' for exit.");
y = input("Enter Year: ");
if y == 'x':
    exit();
else:
    m = input("Enter month: ");
    yy = int(y);
    mm = int(m);
    print("\n",calendar.month(yy,mm));

Using the above program, you can find the calendar of any month from any years, for example, if you will provide 2015 as year and 3 as month, then you will see the calendar of march 2015 with all the date and day.

Here is the sample run of the above Python program illustrating how to display or print calendar of given year and month:

calendar program in python

Now enter a year say 2018 and then a month say 3 (3rd month of the year is march) and then press enter key to see the march's calendar of the year 2018 as shown here in below screenshot:

calendar python

Below is the screenshot of same program with run on python shell:

python display calendar

Program Video with Compile and Run


« Previous Program Next Program »








Tools
Calculator

Quick Links
Signup - Login - Give Online Test