Leap Year Checker
Intermediate · Write the code · from Developing Algorithms: Pseudocode, MOD, and Building Blocks
From the lesson: Developing Algorithms: Pseudocode, MOD, and Building Blocks
An algorithm is a finite set of instructions that accomplishes one specific task, and you can write the same algorithm in plain English, draw it as a flowchart, or type it as code.
Read the lessonA year is a leap year when it is divisible by 4. Years divisible by 100 are the exception: they are not leap years, unless they are also divisible by 400.
Write is_leap_year(year) that returns True or False. Combine divisibility checks (with %) and Boolean operators.
is_leap_year(2024) -> True
is_leap_year(1900) -> Falsedef is_leap_year(year):
# Use % to test divisibility by 4, 100 and 400
pass
What Check runs
Your code runs first, then each of these lines, and 2 more that stay hidden. The output must match exactly.
| Runs | Expected output |
|---|---|
| is_leap_year(2024) | True |
| is_leap_year(2023) | False |
More Algorithm exercises
- Fix the AverageBeginner
- Largest MultipleAdvanced