Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
Python program to check Leap Year|Python language

Python program to check Leap Year|Python language

Posted on November 18, 2020November 18, 2020

Table of Contents

  • Python program to check Leap Year|Python language
    • Leap year program in Python language
      • Make sure whether the given year is leap or not- using if-else
      • Make sure whether the given year is leap or not- using if-elif
      • Make sure whether the given year is leap or not- using Nested if
      • Make sure whether the given year is leap or not- using function

Python program to check Leap Year|Python language

In this article, we will discuss the concept of Python program to check Leap Year|Python language

In this Program, we are going to learn how to make sure the given year whether leap year or not using different methods in Python language.

This is done using if-else , if-elif-else, Nested -if and function in Python language.

Leap year program in Python language

Make sure whether the given year is leap or not- using if-else

In this program, we are going to learn how to make sure the given year whether leap year or not using if-else statements in Python language

Program 1

#Python program to check whether the given year is a leap or not
year=int(input("Enter a year for check leap or not:"))
if((year%400==0) or ((year%4==0)  and (year%100!=0))):
    print("{0} is a leap year".format(year))
else:
    print("{0} is not a leap year".format(year))

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

Case 1

Enter a year for check leap or not:2024
2024 is a leap year

Case 2

Enter a year for check leap or not:2030
2030 is not a leap year

Make sure whether the given year is leap or not- using if-elif

In this program, we are going to learn how to make sure the given year whether leap year or not, using if-else if statements in Python language

Program 2

 

#Python program to check whether the given year is a leap or not
year=int(input("Enter a year for check leap or not:"))
if(year%400==0):
    print("{0} is a leap year".format(year))
elif(year%100==0):
     print("{0} is not a leap year".format(year))
elif(year%4==0):
     print("{0} is a leap year".format(year))
else:
    print("{0} is not a leap year".format(year))

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

Case 1

Enter a year for check leap or not:2064
2064 is a leap year

Case 2

Enter a year for check leap or not:2074
2074 is not a leap year

 

Make sure whether the given year is leap or not- using Nested if

In this program, we are going to learn how to make sure the given year whether leap year or not using Nested if statements in Python language

Program 3

#Python program to check whether the given year is a leap or not
year=int(input("Enter a year for check leap or not:"))
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))

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

Case 1

Enter a year for check leap or not:2030
2028 is a leap year

Case 2

Enter a year for check leap or not:2068
2068 is a leap year

 

Make sure whether the given year is leap or not- using function

In this program, we are going to learn how to make sure the given year whether leap year or not using function in Python language.

Program 4

#Python program to check whether the given year is a leap or not
year=int(input("Enter a year for check leap or not:"))

def leapYear(year):#function definition
    if(year%400==0):
        print("{0} is a leap year".format(year))
    elif(year%100==0):
        print("{0} is not a leap year".format(year))
    elif(year%4==0):
        print("{0} is a leap year".format(year))
    else:
        print("{0} is not a leap year".format(year))
    
leapYear(year)  #function call

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

Case 1

Enter a year for check leap or not:1994
1994 is not a leap year

Case 2

Enter a year for check leap or not:1996
1996 is a leap year

 

Suggested post

Python function

if statements in Python

Nested if statements in Pyton

Operator in Python

Data types in Python

 

Similar post

Java Leap Year Program|Java Program

C Leap Year Program|C Program

C++ Leap Year Program|C++ Program

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes