Python Program to Display Calendar


10xer.co Ad Sponsored

ⓘ Sponsored by 10xer.co

A calendar is a system of organizing days in a year, typically divided into months, weeks, and days. It is used to keep track of dates, holidays, events, and other important information.

A standard calendar consists of 12 months, with each month having a varying number of days. Most months have either 30 or 31 days, but February has 28 days (or 29 days in a leap year, which occurs every four years).


Python Code :

The below Python program displays a calendar for a given month and year using the calendar module:


import calendar

# Prompt user for month and year
year = int(input("Enter year: "))
month = int(input("Enter month: "))

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

Explanation:

  1. The calendar module is imported to allow for calendar functionality.
  2. The user is prompted to enter the year and month they want to display the calendar for.
  3. The calendar.month() function is used to display the calendar for the given month and year. This function takes two arguments: the year and the month as integers.
  4. The print() function is used to display the calendar output.

For Example:


Enter year: 1996
Enter month: 2
   February 1996
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


10xer.co Ad Sponsored

ⓘ Sponsored by 10xer.co