Python Program To Print Calendar Of Any Year
Chapter:
Python
Last Updated:
26-04-2023 16:55:20 UTC
Program:
/* ............... START ............... */
import calendar
# Enter the year for which you want to print the calendar
year = int(input("Enter the year: "))
# Print the calendar for the given year
print(calendar.calendar(year))
/* ............... END ............... */
Output
Enter the year: 2023
2023
January February March
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 1 2 3 4 5 1 2 3 4 5
2 3 4 5 6 7 8 6 7 8 9 10 11 12 6 7 8 9 10 11 12
9 10 11 12 13 14 15 13 14 15 16 17 18 19 13 14 15 16 17 18 19
16 17 18 19 20 21 22 20 21 22 23 24 25 26 20 21 22 23 24 25 26
23 24 25 26 27 28 29 27 28 27 28 29 30 31
30 31
April May June
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 1 2 3 4 5 6 7 1 2 3 4
3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11
10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18
17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25
24 25 26 27 28 29 30 29 30 31 26 27 28 29 30
July August September
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 1 2 3 4 5 6 1 2 3
3 4 5 6 7 8 9 7 8 9 10 11 12 13 4 5 6 7 8 9 10
10 11 12 13 14 15 16 14 15 16 17 18 19 20 11 12 13 14 15 16 17
17 18 19 20 21 22 23 21 22 23 24 25 26 27 18 19 20 21 22 23 24
24 25 26 27 28 29 30 28 29 30 31 25 26 27 28 29 30
31
October November December
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 1 2 3 4 5 1 2 3
2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10
9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17
16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24
23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31
30 31
Notes:
-
The program starts by importing the calendar module from the Python standard library. This module provides functions for working with calendars, such as generating calendars for specific months and years.
- Next, the user is prompted to enter the year for which they want to generate a calendar. The input is then converted from a string to an integer using the int() function.
- The program then uses the calendar module's calendar() function to generate a calendar for the specified year. This function takes two arguments - the year and the width of the output, which is set to 0 in this case to use the default width. The output of this function is a multiline string representing the calendar for the entire year.
- Finally, the program prints the calendar to the console using the print() function.
- Overall, the program is fairly simple and relies mostly on the functionality provided by the calendar module. By prompting the user for input and formatting the output nicely, it provides a user-friendly way to generate calendars for any year.