Python program that displays a calendar for a given month and year:

Created with Sketch.

Python program that displays a calendar for a given month and year:

import calendar

year = int(input("Enter the year: "))
month = int(input("Enter the month (1-12): "))

# Display the calendar
print(calendar.month(year, month))

The program prompts the user to enter the year and month using the input() function, and stores the values in the variables “year” and “month”. It then imports the calendar module and uses the month() function to display the calendar for the given month and year.

You can also use the built-in python module “calendar” to display the calendar of a whole year,

import calendar
year = int(input("Enter the year: "))
print(calendar.calendar(year))

Here it takes the input of year and using the calendar() function it will display the calendar of the whole year.

Please note that the input month should be between 1 to 12, otherwise, it will give an error. You can use any method that suits your need or preference.

Leave a Reply

Your email address will not be published. Required fields are marked *