fastread homefastrread library fastread menu

Python : heck Leap Year

Tutorial by:Rizwan Abdullah      Date: 2016-06-16 00:46:58

❰ Previous Next ❱

Source Code


# Python program to check if the input year is a leap year or not

year = int(input("Enter a year: "))
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 1


Enter a year: 2000
2000 is a leap year

Output 2


Enter a year: 1775
1775 is not a leap year

 

 
 

In this program, we ask the user to input a year and check if it is a leap year or not. Leap years are those divisible by 4. Except those that are divisible by 100 but not by 400. Thus 1900 is not a leap year as it is divisible by 100. But 2000 is a leap year because it if divisible by 400 as well.

❰ Previous Next ❱


Python

Submit Your Thought, Tutorial, Articls etc.

Submit Your Information India's Number one online promotion website