{"id":26032,"date":"2021-12-14T08:43:06","date_gmt":"2021-12-14T03:13:06","guid":{"rendered":"https:\/\/python-programs.com\/?p=26032"},"modified":"2021-12-14T08:43:06","modified_gmt":"2021-12-14T03:13:06","slug":"python-program-for-calendar-isleap-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-calendar-isleap-method-with-examples\/","title":{"rendered":"Python Program for calendar isleap() 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 isleap() Method:<\/strong><\/p>\n calendar.isleap() is a function in Python’s calendar module for creating simple text calendars.<\/p>\n The isleap() method produces a result. If the year is a leap year, True; otherwise, False.<\/p>\n A leap year is a year with one extra day added to bring the calendar year in synchronization with the astronomical or seasonal year.<\/p>\n Syntax:<\/strong><\/p>\n Parameter Values:\u00a0<\/strong><\/p>\n year:<\/strong> This is required. It is a number. The Year to check if it’s a leap year or not.<\/p>\n Return Value:<\/strong><\/p>\n If the year is a leap year, it returns True. Otherwise, False.<\/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 The isleap() method’s operation is described below<\/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 The isleap() method’s operation is described below<\/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. isleap() Method: calendar.isleap() is a function in Python’s calendar module for creating simple text calendars. The isleap() …<\/p>\nisleap(year)<\/pre>\n
Given Year = 2012<\/pre>\n
Checking whether the given year 2012 is a leap or not = True<\/pre>\n
Given Year = 2017<\/pre>\n
Checking whether the given year 2017 is a leap or not = False<\/pre>\n
Program for calendar isleap() 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 = 2012\r\n# Pass the given year as an argument to the isleap() function to check whether\r\n# the given year is a leap year or not.\r\n# Store it in another variable.\r\nrslt = calendar.isleap(gvn_yr)\r\n# Print the result after checking whether the given year is a leap or not.\r\nprint(\"Checking whether the given year\", gvn_yr, \" is a leap or not = \", rslt)\r\n<\/pre>\n
Checking whether the given year 2012 is a leap or not = True<\/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# Pass the given year as an argument to the isleap() function to check whether\r\n# the given year is a leap year or not.\r\n# Store it in another variable.\r\nrslt = calendar.isleap(gvn_yr)\r\n# Check if the above result is equal to True using the if conditional statement.\r\nif rslt == True:\r\n # If it is True, then\u00a0Pass some random year, month, width, lines as\r\n # arguments to the prmonth() method to print the specified month of the\r\n # given leap year.\r\n calendar.prmonth(gvn_yr, 5, 3, 1)\r\n\r\n# Else print \"The given year is not a Leap Year\".\r\nelse:\r\n print(\"The given year\", gvn_yr, \"is not a Leap Year\")\r\n<\/pre>\n
May 2012\r\nMon Tue Wed Thu Fri Sat Sun\r\n 1 2 3 4 5 6\r\n 7 8 9 10 11 12 13\r\n 14 15 16 17 18 19 20\r\n 21 22 23 24 25 26 27\r\n 28 29 30 31<\/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# Pass the given year as an argument to the isleap() function to check whether\r\n# the given year is a leap year or not.\r\n# Store it in another variable.\r\nrslt = calendar.isleap(gvn_yr)\r\n# Print the result after checking whether the given year is a leap or not.\r\nprint(\"Checking whether the given year\", gvn_yr, \" is a leap or not = \", rslt)\r\n<\/pre>\n
Enter some random year = 2017\r\nChecking whether the given year 2017 is a leap or not = False<\/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# Pass the given year as an argument to the isleap() function to check whether\r\n# the given year is a leap year or not.\r\n# Store it in another variable.\r\nrslt = calendar.isleap(gvn_yr)\r\n# Check if the above result is equal to True using the if conditional statement.\r\nif rslt == True:\r\n # If it is True, then\u00a0Pass some random year, month, width, lines as\r\n # arguments to the prmonth() method to print the specified month of the\r\n # given leap year.\r\n calendar.prmonth(gvn_yr, 5, 3, 1)\r\n\r\n# Else print \"The given year is not a Leap Year\".\r\nelse:\r\n print(\"The given year\", gvn_yr, \"is not a Leap Year\")\r\n<\/pre>\n
Enter some random year = 2014\r\nThe given year 2014 is not a Leap Year<\/pre>\n","protected":false},"excerpt":{"rendered":"