{"id":26006,"date":"2021-12-07T18:06:45","date_gmt":"2021-12-07T12:36:45","guid":{"rendered":"https:\/\/python-programs.com\/?p=26006"},"modified":"2021-12-08T20:40:38","modified_gmt":"2021-12-08T15:10:38","slug":"python-program-for-calendar-prmonth-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-calendar-prmonth-method-with-examples\/","title":{"rendered":"Python Program for calendar prmonth() Method with Examples"},"content":{"rendered":"
Calendar Module:<\/strong><\/p>\n The calendar module allows you to output calendars like a program and includes extra calendar-related operations. Calendar module functions and classes make use of an idealized calendar, the current Gregorian calendar extended in both directions indefinitely.<\/p>\n prmonth() Method:<\/strong><\/p>\n The prmonth() method is used to print the month’s calendar.<\/p>\n To generate plain text calendars, class calendar.TextCalendar(firstweekday=0) can be used.The prmonth() method is one of the TextCalendar instance’s methods.<\/p>\n Syntax:<\/strong><\/p>\n Parameter Values:<\/strong><\/p>\n year:<\/strong> This is required. It is a number. It is the year for which the calendar should be created.<\/p>\n month:<\/strong> This is required. It is a number. It is the month for which the calendar should be created.<\/p>\n width:<\/strong> This is Optional. It is a number. The distance between two columns in width. The default value is zero.<\/p>\n lines:<\/strong> This is Optional. It is a number. A blank line separating\u00a0two rows. The default value is zero.<\/p>\n Return Value: <\/strong>A month\u2019s calendar is returned.<\/p>\n Example1:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Calendar Module: The calendar module allows you to output calendars like a program and includes extra calendar-related operations. Calendar module functions and classes make use of an idealized calendar, the current Gregorian calendar extended in both directions indefinitely. prmonth() Method: The prmonth() method is used to print the month’s calendar. To generate plain text calendars, …<\/p>\nprmonth(year, month, width=0, lines=0)<\/pre>\n
Program for calendar prmonth() Method with Examples in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Import calendar module using the import keyword.\r\nimport calendar\r\n# Give the year as static input and store it in a variable.\r\ngvn_yr = 2017\r\n# Give the month as static input and store it in another variable.\r\ngvn_mont = 6\r\n# Call the TextCalendar() function by setting firstweekday=0 and store it in\r\n# another variable.\r\ntxt_calndr = calendar.TextCalendar(firstweekday=0)\r\n# Apply prmonth() method to the above text calendar by passing the given year,\r\n# month as the arguments and store it in another variable.\r\nrslt = txt_calndr.prmonth(gvn_yr, gvn_mont)\r\n# Print the above result.\r\nprint(rslt)\r\n<\/pre>\n
June 2017\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 29 30\r\nNone<\/pre>\n
\n
# Import calendar module using the import keyword.\r\nimport calendar\r\n# Give the year as static input and store it in a variable.\r\ngvn_yr = 2012\r\n# Give the month as static input and store it in another variable.\r\ngvn_mont = 9\r\n# Give the width as static input and store it in another variable.\r\ngvn_widt = 4\r\n# Give the no of lines as static input and store it in another variable.\r\ngvn_lines = 2\r\n# Call the TextCalendar() function by setting firstweekday=0 and store it in\r\n# another variable.\r\ntxt_calndr = calendar.TextCalendar(firstweekday=0)\r\n# Apply prmonth() method to the above text calendar by passing the given year,\r\n# month, width, no of lines as the arguments and store it in another variable.\r\nrslt = txt_calndr.prmonth(gvn_yr, gvn_mont, gvn_widt, gvn_lines)\r\n# Print the above result.\r\nprint(rslt)\r\n<\/pre>\n
September 2012\r\n\r\nMon Tue Wed Thu Fri Sat Sun\r\n\r\n 1 2\r\n\r\n 3 4 5 6 7 8 9\r\n\r\n 10 11 12 13 14 15 16\r\n\r\n 17 18 19 20 21 22 23\r\n\r\n 24 25 26 27 28 29 30\r\n\r\nNone<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Import calendar module using the import keyword.\r\nimport calendar\r\n# Give the year as user input using the int(input()) function and store it in a variable.\r\ngvn_yr = int(input(\"Enter some random year = \"))\r\n# Give the month as user input using the int(input()) function and store it in another variable.\r\ngvn_mont = int(input(\"Enter some random month = \"))\r\n# Call the TextCalendar() function by setting firstweekday=0 and store it in\r\n# another variable.\r\ntxt_calndr = calendar.TextCalendar(firstweekday=0)\r\n# Apply prmonth() method to the above text calendar by passing the given year,\r\n# month as the arguments and store it in another variable.\r\nrslt = txt_calndr.prmonth(gvn_yr, gvn_mont)\r\n# Print the above result.\r\nprint(rslt)<\/pre>\n
Enter some random year = 2015\r\nEnter some random month = 5\r\nMay 2015\r\nMo Tu We Th Fr Sa Su\r\n1 2 3\r\n4 5 6 7 8 9 10\r\n11 12 13 14 15 16 17\r\n18 19 20 21 22 23 24\r\n25 26 27 28 29 30 31\r\nNone<\/pre>\n
\n
# Import calendar module using the import keyword.\r\nimport calendar\r\n# Give the year as user input using the int(input()) function and store it in a variable.\r\ngvn_yr = int(input(\"Enter some random year = \"))\r\n# Give the month as user input using the int(input()) function and store it in another variable.\r\ngvn_mont = int(input(\"Enter some random month = \"))\r\n# Give the width as user input using the int(input()) and store it in another variable.\r\ngvn_widt = int(input(\"Enter some random number = \"))\r\n# Give the no of lines user input using the int(input()) and store it in another variable.\r\ngvn_lines = int(input(\"Enter some random number = \"))\r\n# Call the TextCalendar() function by setting firstweekday=0 and store it in\r\n# another variable.\r\ntxt_calndr = calendar.TextCalendar(firstweekday=0)\r\n# Apply prmonth() method to the above text calendar by passing the given year,\r\n# month, width, no of lines as the arguments and store it in another variable.\r\nrslt = txt_calndr.prmonth(gvn_yr, gvn_mont, gvn_widt, gvn_lines)\r\n# Print the above result.\r\nprint(rslt)\r\n<\/pre>\n
Enter some random year = 2017\r\nEnter some random month = 6\r\nEnter some random number = 5\r\nEnter some random number = 3\r\nJune 2017\r\n\r\n\r\nMon Tue Wed Thu Fri Sat Sun\r\n\r\n\r\n1 2 3 4\r\n\r\n\r\n5 6 7 8 9 10 11\r\n\r\n\r\n12 13 14 15 16 17 18\r\n\r\n\r\n19 20 21 22 23 24 25\r\n\r\n\r\n26 27 28 29 30\r\n\r\n\r\nNone<\/pre>\n","protected":false},"excerpt":{"rendered":"