Flowchart for leap year in python

‹ Return to From Flowcharts to Python Code

Posted on February 28, 2018 by Administrator Posted in

Flowchart for leap year in python


Other challenges you may enjoy...

  • Flowchart for leap year in python
    Leap Year Subroutine
  • Flowchart for leap year in python
    From Flowcharts to Python Code
  • Flowchart for leap year in python
    Weather Statistics Challenge
  • Flowchart for leap year in python
    Leap Year?

Flowchart for leap year in python

Image Information

    Full Size: 474×499px

A leap year is a calendar year with 366 days as it contains an extra day in February. Generally, it is considered a leap year when a year is divisible by 4. But if the same year is also divisible by 100 but not 400, it is not viewed as a leap year. For example, 1600, 1936, 2000, 2004, and 2008 are considered leap years, whereas 1700, 1800, 1935, 1953, 1999 are not considered leap years. Flowchart to check if a year is a leap year or not has been shown below.

1. Flowchart to Check If a Year Is a Leap Year or Not

Flowchart for leap year in python

There are 365 days in a year. A leap year is a year that has 366 days, instead of 365 days. Hence, a leap year has one day extra and occurs every four years. We can check whether a given year is a leap year or not with the following logic. We usually think that a leap year will be divisible by 4, but apart from this, there are other conditions to do this checking. A year will be a leap year only if:
•It is divisible by 4 and not divisible by 100
•It is divisible by 400

Let us consider an example:
2020/4 = 505.
Therefore, 2020 is a leap year.

2000/100 = 20, 2000/400 = 5 and 2000/4 = 500.
Therefore, 2000 is a leap year.

2022/4 = 505.5
Therefore, 2022 is not a leap year.

Let us have a look at the algorithm and flowchart to check whether a given year is a leap year or not.

Algorithm to check whether a given year is a leap year or not:

Step 1: Start Step 2: Read the value of the year to be checked from the user Step 3: Assign the value to a variable, say ‘year’ Step 4: If (year%4 = 0 AND year%100 != 0) OR year%400 = 0, then: Step 4.1: Display “Leap Year” Step 5: Else Step 5.1: Display “Not Leap Year” Step 6: Stop

Explanation:

We start off by taking the value of the year to be checked as user input and store it in a variable say, ‘year’. To check whether the given year is a leap year or not, we will have to check whether the value is divisible by 4 or not. If it is divisible by 4, we must check whether that value is divisible by 100. It will be a leap year only if it is divisible by 4 and not divisible by 100. If the previous condition is not satisfied, we check whether the value is divisible by 400. If any one of the given conditions is true for the value, the year will be a leap year, otherwise, it will not be a leap year.

We check these conditions for the value with the help of the statement: If (year%4 = 0 AND year%100 != 0) OR year%400 = 0. Here, we use the modulus operator to check for divisibility. If this condition holds true, then we display a message saying that the year is a leap year, else we display that the year is not a leap year.

Note: Here ‘%’ is the modulus operator which returns the remainder value after division.

Example:
Let us consider the year 2000:
year = 2000
2000 % 400 = 0
Therefore, 2000 is a leap year.

Let us consider the year 2000:
year = 2007
year / 4 = 2007 / 4 = 501
2007 % 4 = 3
2007 % 400 = 7
Therefore, 2007 is not a leap year.

Flowchart to check whether a given year is a leap year or not:

Flowchart for leap year in python

Remove WaterMark from Above Flowchart

How do you code a leap year in Python?

Example:.
# Default function to implement conditions to check leap year..
def CheckLeap(Year):.
# Checking if the given year is leap year..
if((Year % 400 == 0) or..
(Year % 100 != 0) and..
(Year % 4 == 0)):.
print("Given Year is a leap Year");.
# Else it is not a leap year..

How do you calculate a leap year in a flowchart?

Pseudocode/Algorithm.
If the year is divisible for 400 alone. Then it is a leap year. If not, then it is a non-leap year..
Else if the year given is only divisible by 100, then it is a non-leap year..
Else if the same year is a leap year if the given year is completely divisible by 4..

What is the algorithm for leap year?

The algorithm to determine if a year is a leap year is as follows: Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years, if they are exactly divisible by 400.

Is 1900 a leap year Python?

1900 is not a leap year because it is divisible by 4 and 100, but not by 400. 2000 is a leap year because it is divisble by 4, 100, and 400.