Leap Year Program in Python
Leap year program in Python: Write a program in python to check leap year or not using function and without functions.
Leap year program in Python:
Write a program in python to check leap year or not?
What is Leap Year?
Leap year is a year that comes after every four years.
Actually, it
takes about 1 year 6 hours for an earth to complete one revolution around the
sun, due to which one day increases in every 4 years.
In order to adjust, extra one day is added in the month of February after every 4 years to maintain the balance.
Rules to check weather year is a leap year or not?
A year is said to be leap year if it satisfies following two condition:
- Year is exactly divisible by 4 but it is not a century year (year ending with 00).
- If year is a century year then it must be exactly divisible by 100 as well as 400.
Example:
- 1900 is not a leap year. (Since it is a century year but not divisible by 400).
- 2017 is not a leap year. (Since not divisible by 4)
- 2012 is a leap year. (Because it is divisible by 4)
- 2000 is a leap year. (Since it is a century year and is exactly divisible by 400).
Leap Year Program in Python
Program:
year = int(input("Enter the year\n"))
if (((year%4 == 0) and (year%100 != 0)) or (year%400 == 0)):
print("Leap Year");
else:
print("Not a Leap Year");
Output:
Enter the year
2012
Leap Year
Leap Year Program in Python Using Function
Write a program to check the given year is leap year or not using functions in python
Program:
def leapYear(year):
if (((year%4 == 0) and (year%100 != 0)) or (year%400 == 0)):
print("\n{0} is a Leap Year".format(year));
else:
print("\n{0} is Not a Leap Year".format(year));
year = int(input("Enter the year\n"))
leapYear(year)
Output:
Enter the year
1900
1900 is Not a Leap Year