Leap Year Code.

LEAP YEAR CODE (PYTHON).

What is Leap Year?

An extra day is added to february after every 4 years and the year is callled a leap year for ex.2016,2000,2020 etc.

Conditions for a leap year.

  • The year can be evenly divided by 4, is a leap year, unless:
    • The year can be evenly divided by 100, it is NOT a leap year, unless:
      • The year is also evenly divisible by 400. Then it is a leap year.

Code:-

def is_leap(year):
    leap = False
    if year > 0:#year must be positve integer.
        if year % 100==0 and year % 400==0:#acc to this rule(year that is divisble by 100 and                                                 400 both is a leap year.)
            return True
        if year %4 ==0 and year%100==0:#acc to this rule(yeaar that is divisible by 4 should                                         also be divisle by 100)
            return leap
        if year%4==0:#year is divisible by 4
            return True
        else:
            return leap

year = int(input("Enter year :-"))
print(is_leap(year))

Output:-

Enter year :-2016
True
Enter year :-1992
True
Enter year :-2100
False