Algorithm


1. Start
2. Read the year from the user.
3. If the year is evenly divisible by 4, go to step 4. Otherwise, go to step 7.
4. If the year is evenly divisible by 100, go to step 5. Otherwise, go to step 6.
5. If the year is evenly divisible by 400, go to step 6. Otherwise, go to step 7.
6. The year is a leap year (it has 366 days). Display this information to the user and go to step 8.
7. The year is not a leap year (it has 365 days). Display this information to the user and go to step 8.
8. Stop.

Code Examples

#1 Example- Python Program to Check Leap Year

Code - Python Programming

# Python program to check if year is a leap year or not

year = 2000

# To get year (integer input) from the user
# year = int(input("Enter a year: "))

# divided by 100 means century year (ending with 00)
# century year divided by 400 is leap year
if (year % 400 == 0) and (year % 100 == 0):
    print("{0} is a leap year".format(year))

# not divided by 100 means not a century year
# year divided by 4 is a leap year
elif (year % 4 ==0) and (year % 100 != 0):
    print("{0} is a leap year".format(year))

# if not divided by both 400 (century year) and 4 (not century year)
# year is not leap year
else:
    print("{0} is not a leap year".format(year))
Copy The Code & Try With Live Editor

Output

x
+
cmd
2000 is a leap year

#2 Example- Python Program to Check Leap Year

Code - Python Programming


year = int (input (“Enter any year that is to be checked for leap year: “))

if (year % 4) == 0:

              if (year % 100) == 0:

                             if (year % 400) == 0:

                                            print (“The given year is a leap year”)

                             else:

                                            print (“It is not a leap year”)

              else:

                             print (“It is not a leap year”)

else:     

            print (“It is not a leap year”)
Copy The Code & Try With Live Editor
Advertisements

Demonstration


Python Programing Example to Check Leap Year-DevsEnv