Hello amigos we are here to see about,how to create a python program to find a given year is leap year or not.
LANGUAGE & CONCEPTS INVOLVED:Python & Nested if
LEAP YEAR:
The normal year contains 365 days, but the leap year contains 366 days. Logically, All the years that are perfectly divisible by four called Leap years except the century years.
Century years mean they end with 00 such as 1200, 1300, 2400, 2500, etc. (Obviously they are divisible by 100). For these century years, we have to calculate further to check the Leap year in Python.
EXPLANATION:
The year can be evenly divided by 4
If the year can be evenly divided by 100, it is NOT a leap year,
Unless; the year is also evenly divisible by 400. Then it is a leap year.
The above written is the rules to find a leap year.It should satisfy all the conditions above.We will use nested if…else to solve this problem.
First get an integer input from the user for which they want to find whether it is a leap year or not.Then using if statement check whether it is evenly divisble by 4,if it is true go to check the next statement.
Then using nested if check whether the year is evenly divisible by 100,if this is not true print it is a leap year.If it is true go to check the next condition.
If that year is evenly divisible by 400 then it is a leap year.
In the else part be cautious whether the all the else statement or correctly indented according to their respective if statements.This is process is also cleanly explained in the below flowchart.
FLOWCHART:
For more details refer @www.guvi.com .