We can use the built-in function month() of Calendar module to print a Calendar in Python. The function month() requires two arguments to display a Calendar of given month, first argument is the year in four digits format for example, 2003, 1997, 2018 etc. and second is the month in two digit format, for example 01, 04, 12 etc.
Program to print Calendar in Python
This program prompts the user to enter the year and month and based on the input it calls the month() function which displays the Calendar of the given month for a given year.
# Program published on https://beginnersbook.com # Python program to print Calendar using # Python built-in function import calendar # Enter in format - 2018, 1997, 2003 etc. year = int(input("Enter Year: ")) # Enter in format - 01, 06, 12 etc. month = int(input("Enter Month: ")) # printing Calendar print(calendar.month(year, month))
Output:
Enter Year: 2018 Enter Month: 06 June 2018 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
Source Code in PyCharm IDE:
Leave a Reply