mercredi 2 juin 2021

identifying leap year in python

I am trying to write a python program to identify if a year falls under leap year or not. My code works perfectly fine for all the years but when the year is 1992, it gives an error. How can I improve my code?

Here's the code I've tried:

def is_leap(year):
    leap = False
    
    if (year % 4) == 0:  
        if (year % 100) == 0:  
            if (year % 400) == 0:
                leap = True
            else: leap = False
        else: leap = False
    else:leap = False
    return leap
year = int(raw_input())
print is_leap(year)

Aucun commentaire:

Enregistrer un commentaire