Mastering Python (92 Blogs) Become a Certified Professional
AWS Global Infrastructure

Data Science

Topics Covered
  • Business Analytics with R (26 Blogs)
  • Data Science (20 Blogs)
  • Mastering Python (86 Blogs)
  • Decision Tree Modeling Using R (1 Blogs)
SEE MORE

How to implement Python program to check Leap Year?

Last updated on Nov 27,2024 6.1K Views

6 / 11 Blog from Python Programs

A leap year has an additional day which makes the total number of the days in that year as 366. This additional day in the leap year is added in the month of February. A leap year occurs once in every 4 years. This blog will help you implement a Python program to check leap year or not. Below topics are covered:

How to determine a leap year?

  • If a year is divisible by 4 leaving no remainder then go to the next step. If it is not divisible by 4. It is not a leap year. For example, 1997 is not a leap year.
  • It is a leap year if it is divisible by 4 but not by 100. For example, 2012 is a leap year. If a year is divisible by both 4 and 100, then go to the next step.
  • If a year is divisible by 100, but not divisible by 400. For example, 1900 is not a leap year. If a year is divisible by both the numbers, then it is a leap year. For example- 2000. 

Python Program to Check Leap Year

year = int(input("Enter a year: "))  
 #Getting value for user 
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))
       # Number will be printed as leap year
else:  
   print("{0} is not a leap year".format(year))
   #Number will be printed as Non Leap Year

Output:
Leap year program | Edureka Blogs | Edureka

Input value = 1983

Leap year program | Edureka Blogs | EdurekaInput value = 2000

Leap year program | Edureka Blogs | EdurekaProgram Explanation

  1. Users must first enter the year to be checked for leap year.
  2. The if statement then checks if the year is a multiple of 4 but not 100 or if it is a multiple of 400.
  3. The result is then printed.

With this, we come to an end of this blog on “Python program to check leap year”. I hope it added value to your knowledge of Python. To get in-depth knowledge on Python along with its various applications, you can enroll for live Python Certification Training with 24/7 support and lifetime access.

Upcoming Batches For Data Science with Python Certification Course
Course NameDateDetails
Data Science with Python Certification Course

Class Starts on 21st December,2024

21st December

SAT&SUN (Weekend Batch)
View Details
Data Science with Python Certification Course

Class Starts on 15th February,2025

15th February

SAT&SUN (Weekend Batch)
View Details
Comments
0 Comments

Join the discussion

Browse Categories

webinar REGISTER FOR FREE WEBINAR
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

image not found!
image not found!

How to implement Python program to check Leap Year?

edureka.co