{"id":26013,"date":"2021-12-07T18:06:53","date_gmt":"2021-12-07T12:36:53","guid":{"rendered":"https:\/\/python-programs.com\/?p=26013"},"modified":"2021-12-08T20:41:38","modified_gmt":"2021-12-08T15:11:38","slug":"python-program-for-calendar-pryear-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-calendar-pryear-method-with-examples\/","title":{"rendered":"Python Program for calendar pryear() 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 pryear() Method:<\/strong><\/p>\n The pryear() method prints the calendar for the complete year as returned by formatyear().<\/p>\n To generate plain text calendars, class calendar.TextCalendar(firstweekday=0) can be used.The pryear() 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 width:<\/strong> This is Optional. It is a number. The distance between two columns. 2<\/strong> is the default value.<\/p>\n lines:<\/strong> This is Optional. It is a number. A blank line between two rows. 1<\/strong> is the default value.<\/p>\n c:<\/strong> This is Optional. It is a number. It is the space between two months (column-wise). 6<\/strong> is the default value.<\/p>\n m:<\/strong> This is Optional. It is a number. It is the number of months in a row. 3<\/strong> is the default value.<\/p>\n Return Value:<\/strong> A m-column calendar for the whole year is returned.<\/p>\n Example1:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Note:<\/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. pryear() Method: The pryear() method prints the calendar for the complete year as returned by formatyear(). To …<\/p>\npryear(year, width=2, lines=1, c=6, m=3)<\/pre>\n
Program for calendar pryear() 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 = 2021\r\n# Give the width as static input and store it in another variable.\r\ngvn_widt = 4\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 pryear() method to the above text calendar by passing the given year,\r\n# width,as the arguments and store it in another variable.\r\nrslt = txt_calndr.pryear(gvn_yr, gvn_widt)\r\n# Print the above result.\r\nprint(rslt)\r\n<\/pre>\n
2021\r\n\r\n January February March\r\nMon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun\r\n 1 2 3 1 2 3 4 5 6 7 1 2 3 4 5 6 7\r\n 4 5 6 7 8 9 10 8 9 10 11 12 13 14 8 9 10 11 12 13 14\r\n 11 12 13 14 15 16 17 15 16 17 18 19 20 21 15 16 17 18 19 20 21\r\n 18 19 20 21 22 23 24 22 23 24 25 26 27 28 22 23 24 25 26 27 28\r\n 25 26 27 28 29 30 31 29 30 31\r\n\r\n April May June\r\nMon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun\r\n 1 2 3 4 1 2 1 2 3 4 5 6\r\n 5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13\r\n 12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20\r\n 19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27\r\n 26 27 28 29 30 24 25 26 27 28 29 30 28 29 30\r\n 31\r\n\r\n July August September\r\nMon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun\r\n 1 2 3 4 1 1 2 3 4 5\r\n 5 6 7 8 9 10 11 2 3 4 5 6 7 8 6 7 8 9 10 11 12\r\n 12 13 14 15 16 17 18 9 10 11 12 13 14 15 13 14 15 16 17 18 19\r\n 19 20 21 22 23 24 25 16 17 18 19 20 21 22 20 21 22 23 24 25 26\r\n 26 27 28 29 30 31 23 24 25 26 27 28 29 27 28 29 30\r\n 30 31\r\n\r\n October November December\r\nMon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun\r\n 1 2 3 1 2 3 4 5 6 7 1 2 3 4 5\r\n 4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12\r\n 11 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19\r\n 18 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26\r\n 25 26 27 28 29 30 31 29 30 27 28 29 30 31\r\n\r\nNone<\/pre>\n
It should be noted that the earliest year for which a calendar can be \r\nprepared varies depending on the platform.<\/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 = 2020\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 = 1\r\n# Give the c value as static input and store it in another variable.\r\ngvn_c_val = 3\r\n# Give the m value as static input and store it in another variable.\r\ngvn_m_val = 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 pryear() method to the above text calendar by passing the given year,\r\n# width, lines, c, m values as the arguments and store it in another variable.\r\nrslt = txt_calndr.pryear(gvn_yr, gvn_widt, gvn_lines, gvn_c_val, gvn_m_val)\r\n# Print the above result.\r\nprint(rslt)\r\n<\/pre>\n
2020\r\n\r\n January February\r\nMon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun\r\n 1 2 3 4 5 1 2\r\n 6 7 8 9 10 11 12 3 4 5 6 7 8 9\r\n 13 14 15 16 17 18 19 10 11 12 13 14 15 16\r\n 20 21 22 23 24 25 26 17 18 19 20 21 22 23\r\n 27 28 29 30 31 24 25 26 27 28 29\r\n\r\n March April\r\nMon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun\r\n 1 1 2 3 4 5\r\n 2 3 4 5 6 7 8 6 7 8 9 10 11 12\r\n 9 10 11 12 13 14 15 13 14 15 16 17 18 19\r\n 16 17 18 19 20 21 22 20 21 22 23 24 25 26\r\n 23 24 25 26 27 28 29 27 28 29 30\r\n 30 31\r\n\r\n May June\r\nMon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun\r\n 1 2 3 1 2 3 4 5 6 7\r\n 4 5 6 7 8 9 10 8 9 10 11 12 13 14\r\n 11 12 13 14 15 16 17 15 16 17 18 19 20 21\r\n 18 19 20 21 22 23 24 22 23 24 25 26 27 28\r\n 25 26 27 28 29 30 31 29 30\r\n\r\n July August\r\nMon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun\r\n 1 2 3 4 5 1 2\r\n 6 7 8 9 10 11 12 3 4 5 6 7 8 9\r\n 13 14 15 16 17 18 19 10 11 12 13 14 15 16\r\n 20 21 22 23 24 25 26 17 18 19 20 21 22 23\r\n 27 28 29 30 31 24 25 26 27 28 29 30\r\n 31\r\n\r\n September October\r\nMon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun\r\n 1 2 3 4 5 6 1 2 3 4\r\n 7 8 9 10 11 12 13 5 6 7 8 9 10 11\r\n 14 15 16 17 18 19 20 12 13 14 15 16 17 18\r\n 21 22 23 24 25 26 27 19 20 21 22 23 24 25\r\n 28 29 30 26 27 28 29 30 31\r\n\r\n November December\r\nMon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun\r\n 1 1 2 3 4 5 6\r\n 2 3 4 5 6 7 8 7 8 9 10 11 12 13\r\n 9 10 11 12 13 14 15 14 15 16 17 18 19 20\r\n 16 17 18 19 20 21 22 21 22 23 24 25 26 27\r\n 23 24 25 26 27 28 29 28 29 30 31\r\n 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 width as user input using the int(input()) function and store it in another variable.\r\ngvn_widt = 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 pryear() method to the above text calendar by passing the given year,\r\n# width,as the arguments and store it in another variable.\r\nrslt = txt_calndr.pryear(gvn_yr, gvn_widt)\r\n# Print the above result.\r\nprint(rslt)<\/pre>\n
Enter some random year = 2017 \r\nEnter some random number = 3\r\n 2017\r\n\r\n January February March\r\nMon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun\r\n 1 1 2 3 4 5 1 2 3 4 5\r\n 2 3 4 5 6 7 8 6 7 8 9 10 11 12 6 7 8 9 10 11 12\r\n 9 10 11 12 13 14 15 13 14 15 16 17 18 19 13 14 15 16 17 18 19\r\n 16 17 18 19 20 21 22 20 21 22 23 24 25 26 20 21 22 23 24 25 26\r\n 23 24 25 26 27 28 29 27 28 27 28 29 30 31\r\n 30 31\r\n\r\n April May June\r\nMon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun\r\n 1 2 1 2 3 4 5 6 7 1 2 3 4\r\n 3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11\r\n 10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18\r\n 17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25\r\n 24 25 26 27 28 29 30 29 30 31 26 27 28 29 30\r\n\r\n July August September\r\nMon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun\r\n 1 2 1 2 3 4 5 6 1 2 3\r\n 3 4 5 6 7 8 9 7 8 9 10 11 12 13 4 5 6 7 8 9 10\r\n 10 11 12 13 14 15 16 14 15 16 17 18 19 20 11 12 13 14 15 16 17\r\n 17 18 19 20 21 22 23 21 22 23 24 25 26 27 18 19 20 21 22 23 24\r\n 24 25 26 27 28 29 30 28 29 30 31 25 26 27 28 29 30\r\n 31\r\n\r\n October November December\r\nMon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun\r\n 1 1 2 3 4 5 1 2 3\r\n 2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10\r\n 9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17\r\n 16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24\r\n 23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31\r\n 30 31\r\n\r\nNone\r\n<\/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 width as user input using the int(input()) function and store it in another variable.\r\ngvn_widt = int(input(\"Enter some random number = \"))\r\n# Give the no of lines as user input using the int(input()) function and store it in another variable.\r\ngvn_lines = int(input(\"Enter some random number = \"))\r\n# Give the c value as user input using the int(input()) function and store it in another variable.\r\ngvn_c_val = int(input(\"Enter some random number = \"))\r\n# Give the m value as user input using the int(input()) function and store it in another variable.\r\ngvn_m_val = 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 pryear() method to the above text calendar by passing the given year,\r\n# width, lines, c, m values as the arguments and store it in another variable.\r\nrslt = txt_calndr.pryear(gvn_yr, gvn_widt, gvn_lines, gvn_c_val, gvn_m_val)\r\n# Print the above result.\r\nprint(rslt)<\/pre>\n
Enter some random year = 2005\r\nEnter some random number = 2 \r\nEnter some random number = 1 \r\nEnter some random number = 2 \r\nEnter some random number = 2\r\n\r\n 2005\r\n\r\n January February\r\nMo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su\r\n 1 2 1 2 3 4 5 6\r\n 3 4 5 6 7 8 9 7 8 9 10 11 12 13\r\n10 11 12 13 14 15 16 14 15 16 17 18 19 20\r\n17 18 19 20 21 22 23 21 22 23 24 25 26 27\r\n24 25 26 27 28 29 30 28\r\n31\r\n\r\n March April\r\nMo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su\r\n 1 2 3 4 5 6 1 2 3\r\n 7 8 9 10 11 12 13 4 5 6 7 8 9 10\r\n14 15 16 17 18 19 20 11 12 13 14 15 16 17\r\n21 22 23 24 25 26 27 18 19 20 21 22 23 24\r\n28 29 30 31 25 26 27 28 29 30\r\n\r\n May June\r\nMo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su\r\n 1 1 2 3 4 5\r\n 2 3 4 5 6 7 8 6 7 8 9 10 11 12\r\n 9 10 11 12 13 14 15 13 14 15 16 17 18 19\r\n16 17 18 19 20 21 22 20 21 22 23 24 25 26\r\n23 24 25 26 27 28 29 27 28 29 30\r\n30 31\r\n\r\n July August\r\nMo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su\r\n 1 2 3 1 2 3 4 5 6 7\r\n 4 5 6 7 8 9 10 8 9 10 11 12 13 14\r\n11 12 13 14 15 16 17 15 16 17 18 19 20 21\r\n18 19 20 21 22 23 24 22 23 24 25 26 27 28\r\n25 26 27 28 29 30 31 29 30 31\r\n\r\n September October\r\nMo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su\r\n 1 2 3 4 1 2\r\n 5 6 7 8 9 10 11 3 4 5 6 7 8 9\r\n12 13 14 15 16 17 18 10 11 12 13 14 15 16\r\n19 20 21 22 23 24 25 17 18 19 20 21 22 23\r\n26 27 28 29 30 24 25 26 27 28 29 30\r\n 31\r\n\r\n November December\r\nMo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su\r\n 1 2 3 4 5 6 1 2 3 4\r\n 7 8 9 10 11 12 13 5 6 7 8 9 10 11\r\n14 15 16 17 18 19 20 12 13 14 15 16 17 18\r\n21 22 23 24 25 26 27 19 20 21 22 23 24 25\r\n28 29 30 26 27 28 29 30 31\r\n\r\nNone<\/pre>\n","protected":false},"excerpt":{"rendered":"