BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Python Program to Check whether Year is a Leap Year or not

Last Updated: January 3, 2018 by Chaitanya Singh | Filed Under: Python Examples

In this post, we will write a Python program to check whether the input year(entered by user) is leap year or not.

Python Code

In this program, user is asked to enter a year. Program checks whether the entered year is leap year or not.

# User enters the year
year = int(input("Enter Year: "))

# Leap Year Check
if year % 4 == 0 and year % 100 != 0:
    print(year, "is a Leap Year")
elif year % 100 == 0:
    print(year, "is not a Leap Year")
elif year % 400 ==0:
    print(year, "is a Leap Year")
else:
    print(year, "is not a Leap Year")

Output:
Python Program to check leap Year

Related Posts:

  1. C Program to check leap year
  2. Java Program to check leap year
  3. C++ Program to check leap year using function
  4. Python program to check prime number
  5. Python Program to check even or odd

Top Related Articles:

  1. Python Program to Check If number is Even or Odd
  2. Python Program to Convert Decimal to Hexadecimal
  3. Python Program to Check Vowel or Consonant
  4. Python Program to Convert Celsius To Fahrenheit and Vice Versa
  5. Python program to reverse a String using Recursion

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Comments

  1. Sohaib says

    February 17, 2019 at 3:42 PM

    A bit correction required in the code. It’s displaying incorrect result for 1600/2000 etc.

    #Correct code
    # User enters the year
    year = int(input(“Enter Year: “))

    # Leap Year Check
    if year % 4 == 0 and year % 100 != 0:
    print(year, “is a Leap Year”)
    elif year % 400 ==0:
    print(year, “is a Leap Year”)
    elif year % 100 == 0:
    print(year, “is not a Leap Year”)
    else:
    print(year, “is not a Leap Year”)

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap