Lesson guide
What this Python exercise practices
Is Leap Year is a intermediate practice lesson that focuses on functions, parameters, return values. It is designed to be solved in about 14 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- Function parameters
- Return values
Difficulty and time
- Level
- Intermediate
- Estimated time
- 14 minutes
Practice path
Summary
Determine whether a given year is a leap year following Gregorian rules.
Problem statement
A year is a leap year if it is divisible by 4. However, years divisible by 100 are not leap years unless they are also divisible by 400. Implement is_leap_year(year) that applies these rules and returns True for leap years and False otherwise.
Task
Write a function that returns True if a year is a leap year and False otherwise, using if/elif/else logic.
Examples
Year 2000 is a leap year
Input
2000
Output
True
Explanation
2000 is divisible by 400, so it's a leap year.
Input format
A single integer representing the year (e.g., 2024).
Output format
Return True if the year is a leap year, otherwise return False.
Constraints
Year is an integer. You may assume typical historical year ranges (positive and negative integers allowed), but apply the divisibility rules strictly.
Samples
Sample input 0
1900
Sample output 0
False
Explanation 0
1900 is divisible by 100 but not by 400, so it's not a leap year.
AI assistant
Ask me anything!
Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.
Chat history is temporary and will not be saved.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.