What is a Leap year ?
Generally we have 28 days in the month of February and overall 365 days in a year. But a leap year have 29 days in the month of February and overall 366 days in a year. For every four years we get a leap year.
Conditions to be a leap Year.
Year divisible by 4 is a leap year until it is not divisible by 100 (century year{year ends with 00} is not a leap year until it is divisible by 400, if it is divisible by 400 then it is a leap year.
Explanation :
For a non century year if year divisible by 4 then it is a leap year.
For a non century year if year not divisible by 4 then it is not a leap year.
If year is a century year then it is not a leap year.
Century year is said to be a leap year if it is divisible by 400 .
Input :
enter a year 2400
Output :
2400 is a leap year
Program to find leap Year or not in Python
#program to say leap year or not
year=int(input("enter a year "))
if year%4==0:
if year%100==0:
if year%400==0:
print(year,"is a leap year.")
else:
print(year,"is not a leap year.")
else:
print(year,"is a leap year.")
else:
print(year,"is not a leap year.")
#----method 2------using ternary operator---------#
year=int(input())
print("leap year"if (year%4==0) else "not a leap year")
Output :
enter a year 2400
2400 is a leap year.
Comments
Post a Comment
Type Your Comments !
Please do not enter any spam link in the comment box.