In this tutorial you will learn about the Python Program to Display Calendar and its application with practical example.
In this tutorial, we will learn to create a Python Program to Display Calendar using python Programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following Python programming topics:
- Python Operator.
- Basic Input and Output
- Basic Python programming.
- Python Data type.
- Python in-built Functions.
- Loops in Python.
- Built in Modulus
Python Program to Display Calendar
In this program we will create a program in which we will Display Calendar .We would first declared and initialized the required variables. Next, we would prompt user to input the values later we will Display Calendar.
1 2 3 4 5 6 7 8 9 10 11 |
# Python program to display calendar of # given month and the year # import module import calendar yy = int(input("enter year's value in yy fromat")) mm = int(input("enter month's value in mm format")) # displaying the calendar... print(calendar.month(yy, mm)) |
Output
As you can see we have taken value of year in ‘yy’ format and month in ‘mm’ format in display the inputted year and month using in-built calendar.month() Method .
In the above program, we have first declared and initialized a set variables required in the program.
- yy = it will hold Year value.
- mm= it will hold months value.
And in the next statement user will be prompted to enter two values of “Year” and “Month” and assigned them to variables ‘yy‘ and ‘mm’ respectively.
In this program above, we import the module called “Calendar”.
In which built-in method “month() ” inside this module we take the value of year and the month as an arguments (Parameter) and displays the calendar for that month and that year.
Python Program to Display Calendar.
In our program we will create a program in which we will Display whole year Calendar .We would first declared and initialized the required variables. Next, we would prompt user to input the values later we will Display Calendar.
1 2 3 4 5 6 7 8 9 10 |
# Python program to display calendar of # given year # import module import calendar yy = int(input("enter value or year in -yy- Format")) # display the calendar print(calendar.calendar(yy)) |
Ouptput
In this program First we import the calendar module. The built-in function calendar () inside the module takes in the year and displays the whole year calendar for that year.