Python Leap Year
and / or Practice

Leap year logic

Calendars add Feb 29 every 4 years — except century years unless divisible by 400. Real calendar apps use the same boolean rules you will code.

Picture this: leap year rules

Divisible by 4, but century years need 400.

yeare.g. 2024
→
÷ 4?maybe leap
→
÷ 100?careful
→
÷ 400?century leap

In easy words: What is this task?

You decide whether a year has 28 or 29 days in February by checking divisibility rules.

Where this is used

Used in calendars, reminder apps, scheduling systems, subscriptions, and date calculations.

Real world: birthday on Feb 29

People born on leap day celebrate on Feb 28 or Mar 1 in common years. Apps must know 2024 → Yes, 1900 → No, 2000 → Yes before scheduling reminders.

February in the calendar

2024 → Yes (29 days in February)
·if (y % 4 == 0 and y % 100 != 0) or (y % 400 == 0):

Rule breakdown

  • Divisible by 4 → usually leap.
  • Except century years (÷100) unless also ÷400.
  • Practice prints Yes or No for input year.

Example Program

1y = int(input())
2if (y % 4 == 0 and y % 100 != 0) or (y % 400 == 0):
3print("Yes")
4else: print("No")