Coders Packet

python program to check leap year

By Karthik Nagisetty

For finding whether the year is leap year or not by using python program. Generally the leap year is exactly divisible by 4 except for century years(years ending with 00).

python program to check leap year

A year is called a leap year if it contains an additional day which makes the number of days in that year 366. this additional day is added in February which makes it 29 days long.

How do you determine if a year is a leap year or not?
you should follow the following steps to determine whether a year is a leap year or not.
1. If a year is evenly divisible by 4 means having no remainder then go to the next step if it is not divisible by 4. It is not a leap year. For example:1997 is not a leap year.
2. If a year is divisible by 4, but not by 100. For example, 2000 is a leap year. If a year is divisible by both 4 and 100, go to the next step.
3. If a year is divisible by 100, but not by 400. For example,3000 is not a leap year. If a year is divisible by both, then it is a leap year.    

 

 

def checkleap(year):
    if((year % 400==0)or
       (year % 100!=0)and
       (year % 4==0)):
        print("Given year is a leap year")
    else:
        print("Given year is not a leap year")
year=int(input("Enter the number:"))
checkleap(year)

 

 

 

 

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Karthik Nagisetty (karthik)

Download packets of source code on Coders Packet