- Read the question carefully (twice).
- Break the task into the smallest steps.
- Sketch or write pseudocode before coding.
- Start small — test as you go.
- Check your solution with different cases.
Problem Description
Some years have 366 days instead of 365 – these are called leap years.
Leap years are special because they add an extra day in February (February 29).
The rules for leap years are:
- A year is a leap year if it is divisible by 4.
- But if the year is also divisible by 100, then it is NOT a leap year…
- …unless it is also divisible by 400. In that case, it is a leap year.
Examples:
- 2000 → leap year (divisible by 400)
- 1900 → not a leap year (divisible by 100, but not 400)
- 2024 → leap year (divisible by 4, not by 100)
- 2023 → not a leap year
Learning Goals
By completing this problem, you should be able to:
- Use modulus (
<strong>%</strong>) to check divisibility. - Apply if / else if / else statements.
- Write a program that gives clear output to the user.
- Test your code with different inputs to confirm correctness.
Tasks
Task 1: Simple Divisibility by 4
- Write a program that asks the user for a year.
- If the year is divisible by 4, print
"This is a leap year (maybe!)." - Otherwise, print
"This is NOT a leap year."
Task 2: Add the 100-Year Rule
Update your program so that it:
- Checks if the year is divisible by 100.
- If it is divisible by 100 but not by 400, print
"This is NOT a leap year."
Task 3: Add the 400-Year Rule
Update your program again:
- If the year is divisible by 400, it is a leap year.
- Otherwise, follow the earlier rules.
Now your program can correctly decide for any year.
Task 4: Test Your Program
Run your program with these years and record the results:
2000→ Leap year1900→ Not a leap year2020→ Leap year2023→ Not a leap year2400→ Leap year
Extension Challenge (Optional)
- Update your program so that it keeps asking for years until the user types
"quit". - Allow the user to enter multiple years at once (for example:
2000, 2023, 1900) and check each one. - Add a message that tells the user how many leap years they entered.
✅ Success Criteria:
- You can explain the rules of leap years.
- Your program correctly determines if a year is a leap year.
- Your program works for the provided test cases.
- (Extension) Your program can handle multiple inputs and repeats until the user quits.