You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This problem involves determining whether a given year is a leap year based on the rules defined in the Gregorian calendar. In a leap year, an extra day (February 29) is added to the calendar to account for the fact that a year is not exactly 365 days, but approximately 365.25 days. The task is to implement a function is_leap(year) that takes an integer year as input and returns True if the year is a leap year and False otherwise.
Key Considerations:
Leap Year Rules:
If the year is divisible by 4, it's usually a leap year.
However, if the year is also divisible by 100, it is not a leap year, unless:
The year is divisible by 400. If it is, then it is a leap year.
In short, If the year is divisible by 4, but not divisible by 100, or if it is divisible by 400, then it is a leap year.
This logic means:
Years like 2000 and 2400 are leap years because they are divisible by 400.
Years like 1800, 1900, 2100, 2200, 2300, and 2500 are not leap years because they are divisible by 100 but not by 400.
Years like 1996, 2004, and 2008 are leap years because they are divisible by 4 but not by 100.
Constraints:
The input year is a positive integer representing a year in the Gregorian calendar.
The year can be any valid integer that represents a calendar year, including edge cases like very old years or very large years.
The function must efficiently handle the input year and output the correct Boolean value.
Sample Test Cases:
Test Case 1:
Input: 1990
Output: False
Explanation: 1990 is not divisible by 4, hence it is not a leap year.
Test Case 2:
Input: 2000
Output: True
Explanation: 2000 is divisible by 400, so it is a leap year.
Test Case 3:
Input: 2100
Output: False
Explanation: 2100 is divisible by 100 but not by 400, so it is not a leap year.
Test Case 4:
Input: 2004
Output: True
Explanation: 2004 is divisible by 4 but not by 100, so it is a leap year.
The text was updated successfully, but these errors were encountered:
Leap Year Problem
This problem involves determining whether a given year is a leap year based on the rules defined in the Gregorian calendar. In a leap year, an extra day (February 29) is added to the calendar to account for the fact that a year is not exactly 365 days, but approximately 365.25 days. The task is to implement a function
is_leap(year)
that takes an integeryear
as input and returnsTrue
if the year is a leap year andFalse
otherwise.Key Considerations:
Leap Year Rules:
In short, If the year is divisible by 4, but not divisible by 100, or if it is divisible by 400, then it is a leap year.
This logic means:
Constraints:
Sample Test Cases:
Test Case 1:
False
Test Case 2:
True
Test Case 3:
False
Test Case 4:
True
The text was updated successfully, but these errors were encountered: