Description

The year which has 366 days is called a leap year. This additional day is added in february which makes it 29 days long. A leap year occurred once every 4 years.

Algorithm to check of leap year in Python

  1. Take input of year from users.
  2. if( ( year % 400 == 0 ) or ( year % 4 == 0 ) and ( year % 100 != 0 ) ) then print("GIven Year is Leap Year")
  3. Otherwise print("GIven Year is Not leap Year")

Code of Leap year in python

year = int(input("Enter the year to check Leap year or not : "))

if year % 4 == 0:
    if year % 100 == 0:
        if year % 400 == 0:
            print("Given Year is Leap Year")
        else:
            print("Given Year is Not Leap Year")
    else:
        print("Given Year is Leap Year")
else:
    print("Given Year is Not Leap Year")

Method 2

year = int(input("Enter the year to check Leap year or not : "))

if year % 4 == 0 or year % 100 == 0 or year % 400 == 0:
    print("Given Year is Leap Year")
else:
    print("Given Year is Not Leap Year")

Program to check if year is a leap year or not

year = int(input("Enter the year to check Leap year or not : "))

if year % 400 == 0 and year % 100 == 0:
    print(f"{year} is leap Year")
elif year % 4 == 0 and year % 100 != 0:
    print(f"{year} is leap Year")
else:
    print(f"{year} is not leap year")

using function check leap year or not in python

def leap_year_check(year):
    if ((year % 400 == 0) or (year % 100 != 0) and (year % 4 == 0)):
        return True
    else:
        return False

year = int(input("Enter the year to check Leap year or not : "))

r = leap_year_check(year)
if(r):
    print("Given Year is Leap Year")
else:
    print("Given Year is Not leap Year")

Thanks for Reading...

Please Given Your Advise in Comment Box...

Comments

Login is mandatory to comment Please login

Recommended Posts

Fibonacci Series | Fibonacci Sequence in Python

Fibonacci numbers ( series ) is a set of numbers that start with 1 or 0 followed by a 1 proceeds on the rule that each number.

Find maximum of two number in python programming language

Maximum of two number in Python - Using max() function , Using if else statement, Using Ternary operator and Using Lambda function.