In this simple python program, we have to display a calendar of a month. It's a beginner-level python program.
To understand this example, you should have knowledge of the following Python programming topics:
To display a calendar, we have a predefined module in python called a calendar, which displays the calendar. The syntax of the
calendar module is like (calendar.month(yy,mm)) where'
We have many predefined operations on this calendar module in python language. For example,
There are many more methods to use with the calendar module, which is described in the calendar module tutorial.
In this simple python program, we accept the values for year and month from the user and import the calendar module. Finally, we call the print function and call the
calendar module to print the year and month
print(calendar.month(yy,mm)). Let us break the code
STEP 1: Import the python built-in module called calendar, which has many accepted operational methods we discussed above in the description.
STEP 2: Accept the year and month from the user using the input method as a string and convert that to an integer using int in python language.
STEP 3: Just use the operation month(yy, mm) with the calendar module like a calendar. month(yy, mm) to print a specific month of a specific year.
import calendar yy = int(input("Enter year: ")) mm = int(input("Enter month: ")) print(calendar.month(yy,mm))
Enter year: 2020 Enter month: 5 May 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