Skip to content
Home » Check Leap Year using nested if-else

Check Leap Year using nested if-else

Learn about Check Leap Year using nested if-else in the below code example. Also, refer to the comments in the code snippet to get a detailed view about what’s actually happening.

Check Leap Year using nested if-else

A leap year, with the exception of century years, is exactly divisible by four (years ending with 00). A leap year occurs only when the century year is precisely divisible by 400. The program below determines whether or not the given year is a leap year.

Program:

# Program to check year is a leap year or not

# year input
year = int(input('Enter a year: '))

# check leap year or not
if(year % 4) == 0:
    if(year % 100) == 0:
        if(year % 400) == 0:
            print('{0} is a leap year'.format(year))
        else:
            print('{0} is not a leap year'.format(year))
    else:
        print('{0} is a leap year'.format(year))
else:
    print('{0} is not a leap year'.format(year))

Output:

Enter a year: 2000
2000 is a leap year

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Code : Leap Year Program in Python