Check if a Given Year is a Leap Year
Apply the Gregorian leap-year rule with conditions. Students trace ordinary years, century exceptions, and multiples of four hundred without date libraries.
1# Take year as input2year = int(input("Enter a year: "))34# Check if leap year5if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):6 print("Leap year")7else:8 print("Not a leap year")
Output
Enter a year: 2024 Leap year Enter a year: 2023 Not a leap year Enter a year: 2000 Leap year
In this one
- Apply leap-year exceptions
- Group conditions with parentheses
- Test century boundaries
How it works
- 1
Read the year as an integer.
- 2
Check the noncentury multiple-of-four rule.
- 3
Also accept multiples of four hundred.
Edge cases
Is 1900 a leap year?
Is 1900 a leap year?
No. It is a century year not divisible by 400.
Is 2000 a leap year?
Is 2000 a leap year?
Yes. The second part of the condition is true.
What's going on
A leap year needs a more careful rule than divisibility by four alone. Most multiples of four qualify, but century years need to be divisible by four hundred.
The parenthesized and group accepts multiples of four that are not multiples of one hundred. The or group restores years such as 2000. Thus 2024 and 2000 qualify, while 1900 and 2023 do not.
Is 1900 a leap year? No. It is a century year not divisible by 400.
Is 2000 a leap year? Yes. The second part of the condition is true.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Why is divisibility by four not enough?
Pick an answer to check it.
Question 2
Is 1900 a leap year?
Pick an answer to check it.
Questions people ask
Is 1900 a leap year?
No. It is a century year not divisible by 400.
Is 2000 a leap year?
Yes. The second part of the condition is true.
Why is divisibility by four not enough?
Century years have an exception.
๐Related Content
- ๐
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- ๐
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- ๐ป
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum