|Artificial Intelligence Tutorial|
|Machine Learning Projects Tutorial||Python Video tutorial|
|Computer Graphics Video Tutorial||C++ Video Tutorial|
|Big Data Analytics Video Tutorial||Soft Computing Video Tutorial|
|Placement Video Tutorial||Java Video Tutorial|
Python Program to check whether the Year is Leap Year or Not
Write a Python program that has a method called is_leap_year() which accepts the year as its argument and checks whether the year is a leap year or not and displays an appropriate message on the screen.
Logic of Leap year program:
if the year is divisible by 400 then the year is a leap year
Example: 1600, 2000, 2400, and so on
if the year is divisible by 4 but not by 100 is a leap year
Leap Year: 2004, 2008, 2012, 2016, 2020, and so on
Not Leap Year: 1800, 1900, 2100 are not leap years
1. First we, define the is_leap_year() method, which accepts an argument say a year.
2. Next, we check whether the year is a leap year or not a leap year.
2.1. If Year is a leap year, display a message as the year is a leap year.
2.2. If Year is not a leap year, display a message as the year is not a leap year.
3. Next, read the year from the user and pass the year to the is_leap_year() method.
Source code of Python Program to check whether the Year is Leap Year or Not
def is_leap_year(year): if ((year % 4 == 0 and year % 100 != 0) or year % 400 ==0): print (year, "is a leap year") else: print (year, "is not a leap year") year = int (input("Enter the year: ")) is_leap_year(year)
Enter the year: 2000
2000 is a leap year
Enter the year: 1600
1600 is not a leap year
Enter the year: 2020
2020 is a leap year