{"id":26035,"date":"2021-12-14T08:43:08","date_gmt":"2021-12-14T03:13:08","guid":{"rendered":"https:\/\/python-programs.com\/?p=26035"},"modified":"2021-12-14T08:43:08","modified_gmt":"2021-12-14T03:13:08","slug":"python-program-for-calendar-leapdays-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-calendar-leapdays-method-with-examples\/","title":{"rendered":"Python Program for calendar leapdays() 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 leapdays() Method:<\/strong><\/p>\n calendar.leapdays() is a function in Python\u2019s calendar module for creating simple text calendars.<\/p>\n The leapdays() method returns the number of leap years in a given range of years. Syntax:<\/strong><\/p>\n Parameter Values:\u00a0<\/strong><\/p>\n year1, year2:<\/strong> These are required. They are numbers. They are the years to get the number of leap years(range).<\/p>\n Return Value:<\/strong> The number of leap years in a given range is returned.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/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. leapdays() Method: calendar.leapdays() is a function in Python\u2019s calendar module for creating simple text calendars. The leapdays() …<\/p>\n
\nThis function works for time spans of a century change.<\/p>\nleapdays(year1, year2)<\/pre>\n
Given lower limit year = 2013\r\nGiven upper limit year = 2025<\/pre>\n
The number of leap years in a given range{ 2013 , 2025 } = 3<\/pre>\n
Given lower limit year = 1999\r\nGiven upper limit year = 2002<\/pre>\n
The number of leap years in a given range{ 1999 , 2002 } = 1<\/pre>\n
Program for calendar leapdays() 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 lower limit year as static input and store it in a variable.\r\ngvn_yr1 = 2013\r\n# Give the upper limit year as static input and store it in another variable.\r\ngvn_yr2 = 2025\r\n# Pass the given lower and upper limits as the arguments to the leapdays() function\r\n# to get the number of leap years in a given range.\r\n# Store it in another variable.\r\nrslt = calendar.leapdays(gvn_yr1, gvn_yr2)\r\n# Print the number of leap years in a given range.\r\nprint(\r\n \"The number of leap years in a given range{\", gvn_yr1, \",\", gvn_yr2, \"} = \", rslt)\r\n<\/pre>\n
The number of leap years in a given range{ 2013 , 2025 } = 3<\/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 lower limit year as user input using the int(input()) function and store it in a variable.\r\ngvn_yr1 = int(input(\"Enter some random year = \"))\r\n# Give the upper limit year as user input using the int(input()) function and store it another variable.\r\ngvn_yr2 = int(input(\"Enter some random year = \"))\r\n# Pass the given lower and upper limits as the arguments to the leapdays() function\r\n# to get the number of leap years in a given range.\r\n# Store it in another variable.\r\nrslt = calendar.leapdays(gvn_yr1, gvn_yr2)\r\n# Print the number of leap years in a given range.\r\nprint(\r\n \"The number of leap years in a given range{\", gvn_yr1, \",\", gvn_yr2, \"} = \", rslt)\r\n<\/pre>\n
Enter some random year = 1999\r\nEnter some random year = 2002\r\nThe number of leap years in a given range{ 1999 , 2002 } = 1<\/pre>\n","protected":false},"excerpt":{"rendered":"