In this program we are going to test whether a given year is a leap year or not.

Leap year is the year which is divisible by 4 except the century year that is ending with 00.

The century year is the leap year only if it is perfectly divisible by 400. 

For example:

2017 is not a leap year.

2000 is a leap year.

    Algorithm:

  1. Input the year from the user.
  2. Check using if statements , whether it is a leap year or not.
  3. Print the final result
  4. Exit

Code:

n= int(input("Enter the year you want to check?"))

if (n%4==0):

    if (n%100==0):

        if (n%400==0):

            print("It is a leap year")

        else:

            print("It is not a leap year")

    else:

        print("It is a leap year")

else:

    print("It is not a leap year")

Output:

Enter the year you want to check? 1996

It is a leap year


Enter the year you want to check? 1900

It is not a leap year

Report Error/ Suggestion

Related Posts:

[yuzo_views]











CopyRight © 2019

CopyRight © 2019