Leap year
EasyBasics5 min
Write a function isLeapYear(year) that returns true if the year is a leap year and false if it is not.
- The parameter
yearis an integer from 1 to 9999. - A year is a leap year if it divides by 4 with no remainder:
2024is a leap year,2023is not. - Exception: a year that divides by 100 is a leap year only if it also divides by 400.
1900is not a leap year,2000is. - Return a boolean:
trueorfalse, not the string'true'.
Examples
isLeapYear(2024)Returns true
isLeapYear(1900)Returns false
isLeapYear(2000)Returns true
Asked at Infosys · Source
Loading the editor...
- Input
isLeapYear(2024)Expectedtrue - Input
isLeapYear(2023)Expectedfalse - Input
isLeapYear(1900)Expectedfalse - Input
isLeapYear(2000)Expectedtrue
Hidden tests run on Submit