{"id":7291,"date":"2023-11-01T10:19:08","date_gmt":"2023-11-01T04:49:08","guid":{"rendered":"https:\/\/python-programs.com\/?p=7291"},"modified":"2023-11-10T12:11:23","modified_gmt":"2023-11-10T06:41:23","slug":"program-to-display-calendar-in-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/program-to-display-calendar-in-python\/","title":{"rendered":"Program to Display Calendar in Python"},"content":{"rendered":"
To work with date-related tasks, Python has a built-in function called calendar. In this posts, you will learn how to display the calendar for a specific date.<\/p>\n
The calendar class in Python’s Calendar module allows for calculations based on date, month, and year for a variety of tasks. Furthermore, the Text Calendar and HTML Calendar classes in Python allow you to customize the calendar and use it as needed.<\/p>\n
Examples:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explore more instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n To print a calendar in Python, we can use the built-in function month() from the Calendar module. To display a Calendar for a given month, the function month() requires two arguments: the first is the year in four-digit format, such as 2003, 1997, 2018, and the second is the month in two-digit format, such as 01, 04, 12, and so on.<\/p>\n This program prompts the user for the year and month, and then calls the month() function, which displays the Calendar for the given month for a given year, based on the input.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n The calendar module is imported in the program\u00a0 below. The module’s built-in function calender() accepts a year and displays the calendar for that year.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n To work with date-related tasks, Python has a built-in function called calendar. In this posts, you will learn how to display the calendar for a specific date. The calendar class in Python’s Calendar module allows for calculations based on date, month, and year for a variety of tasks. Furthermore, the Text Calendar and HTML Calendar …<\/p>\ngiven year=2001 month =2<\/pre>\n
February 2001\r\nMo Tu We Th Fr Sa Su\r\n 1 2 3 4\r\n 5 6 7 8 9 10 11\r\n12 13 14 15 16 17 18\r\n19 20 21 22 23 24 25\r\n26 27 28\r\n<\/pre>\n
Program to Display Calendar in Python<\/h2>\n
\n
1)Displaying the month<\/h3>\n
# importing calendar function\r\nimport calendar\r\n\r\n# given year\r\ngiven_year = 2001\r\n\r\n# given month\r\ngiven_month = 2\r\n\r\n# printing the calendar of given year and month\r\nprint(calendar.month(given_year, given_month))\r\n<\/pre>\n
February 2001\r\nMo Tu We Th Fr Sa Su\r\n 1 2 3 4\r\n 5 6 7 8 9 10 11\r\n12 13 14 15 16 17 18\r\n19 20 21 22 23 24 25\r\n26 27 28<\/pre>\n
2)Displaying the year<\/h3>\n
# importing calendar function\r\nimport calendar\r\n# given year\r\ngiven_year = 2001\r\n# printing the calendar of given year\r\nprint(calendar.calendar(given_year))\r\n<\/pre>\n
2001\r\n \r\n January February March\r\nMo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su\r\n 1 2 3 4 5 6 7 1 2 3 4 1 2 3 4\r\n 8 9 10 11 12 13 14 5 6 7 8 9 10 11 5 6 7 8 9 10 11\r\n15 16 17 18 19 20 21 12 13 14 15 16 17 18 12 13 14 15 16 17 18\r\n22 23 24 25 26 27 28 19 20 21 22 23 24 25 19 20 21 22 23 24 25\r\n29 30 31 26 27 28 26 27 28 29 30 31\r\n\r\n April May June\r\nMo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su\r\n 1 1 2 3 4 5 6 1 2 3\r\n 2 3 4 5 6 7 8 7 8 9 10 11 12 13 4 5 6 7 8 9 10\r\n 9 10 11 12 13 14 15 14 15 16 17 18 19 20 11 12 13 14 15 16 17\r\n16 17 18 19 20 21 22 21 22 23 24 25 26 27 18 19 20 21 22 23 24\r\n23 24 25 26 27 28 29 28 29 30 31 25 26 27 28 29 30\r\n30\r\n\r\n July August September\r\nMo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su\r\n 1 1 2 3 4 5 1 2\r\n 2 3 4 5 6 7 8 6 7 8 9 10 11 12 3 4 5 6 7 8 9\r\n 9 10 11 12 13 14 15 13 14 15 16 17 18 19 10 11 12 13 14 15 16\r\n16 17 18 19 20 21 22 20 21 22 23 24 25 26 17 18 19 20 21 22 23\r\n23 24 25 26 27 28 29 27 28 29 30 31 24 25 26 27 28 29 30\r\n30 31\r\n\r\n October November December\r\nMo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su\r\n 1 2 3 4 5 6 7 1 2 3 4 1 2\r\n 8 9 10 11 12 13 14 5 6 7 8 9 10 11 3 4 5 6 7 8 9\r\n15 16 17 18 19 20 21 12 13 14 15 16 17 18 10 11 12 13 14 15 16\r\n22 23 24 25 26 27 28 19 20 21 22 23 24 25 17 18 19 20 21 22 23\r\n29 30 31 26 27 28 29 30 24 25 26 27 28 29 30\r\n 31\r\n<\/pre>\n
\nRelated Programs<\/strong>:<\/p>\n\n