Logic Building
# Take year as input
year = int(input("Enter a year: "))
# Check if leap year
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print("Leap year")
else:
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
Leap year rules:
- Divisible by 4 AND not divisible by 100, OR
- Divisible by 400
Key Concepts:
- Use
orto combine two conditions - First condition: divisible by 4 but not by 100
- Second condition: divisible by 400
- Either condition makes it a leap year