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

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

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 *

Python Tutorial

Introduction

  • Python Tutorial
  • Python Introduction
  • Install Python
  • PyCharm IDE Installation
  • Python in PyCharm
  • Python Comments
  • Python Variables
  • Python Keywords & Identifiers
  • Python data types

Flow Control

  • Python If
  • Python if..else
  • Python if..elif..else
  • Python Nested If
  • Python for loop
  • Python while loop
  • Python break
  • Python continue
  • Python pass

Python Functions

  • Python Functions
  • Python Recursion

Python Datatypes

  • Python Numbers
  • Python List
  • Python Strings
  • Python Tuple
  • Python Dictionary
  • Python Set

Python OOPs

  • Python OOP
  • Python Class & Object
  • Python Constructors

Python Examples

  • Python Programs

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap