Check value

Python program for check whether given year is leap using function

Python program for check whether given year is leap using function

In this article, we will discuss the concept of Python program for check whether given year is leap using function

In this post, we are going to learn how to write a program to check  the given year is leap or not using function in  Python programming language.

Check if the given year is a leap

check whether given year is leap using function

What is leap year

A normal year contains 365 days but a leap year contains 366 days

leap year is occurring once every four years, which has 366 days including 29 February as an intercalary day. it is called leap year

 

Century year

The century year is ending with 00

Ex 2000, 2100, 2200

a century year may be a leap year but it is not compulsory

 

How to find the leap year

if The given year is perfectly divisible by 4 , it is a leap year(except century year)

only if is perfectly divisible by 400, the century year is a leap year,
a century year should be divisible by 4 and 100 both
a non century year should be divisible only by 4

 

Code to check leap year using function

Here, The program allows the user to enter the year and then it will check the year is a leap year or not, using function in Python language

Program 1

#Python program to check leap year using if statements
year=int(input("Please enter the year you wish: "));
#Ask input from the user and store the variable year

def leapYear(year):#function definition
     if ((year%400==0)or((year%4==0)and(year%100!=0))):
    #if it is true display leap year
    #if it is false move to else part
        print("%d is a leap year"%year);
     else:
        print("%d is not a leap year"%year);

leapYear(year)#Calling the function

When the above code is executed, it produces the following result

Case 1

Please enter the year you wish: 2020
2020 is a leap year

 

Case 2

Please enter the year you wish: 2030
2030 is not a leap year

 

Suggested post

if statements in Python  language

Nested if statements in Python language

Data type in Python language

Operator in Python language

 

Similar post

Java program to find leap year

C program to find leap year

C++ program to find leap year

Python program to find leap year

 

C program for check whether given year is leap using function
C# program to check if a number is prime or not
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

6 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

6 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

6 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

9 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

1 year ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

1 year ago