Python Program to Check Leap Year | Leap Year Program in Python

Posted in

Python Program to Check Leap Year | Leap Year Program in Python
vinaykhatri

Vinay Khatri
Last updated on November 21, 2024

    In this Python tutorial, you will learn how to write a python program to check a leap year. Here in this article we have provided a python source code which output if the user entered year is a leap year or not.

    Prerequisite To Leap Year Program in Python

    Steps

    • First, we ask the user to enter the 4 digit year.
    • Using the int() function we will convert the entered string into an integer value.
    • Using the if....elif nested statement and arithmetic modules operator we check for conditions.

    Leap Year Program in Python

    Python Code

    year = int(input("Enter the Year: "))
    if year%4==0:
        if year%100==0:
            if year%400==0:
                print(year, "is a leap year")
            else:
                print(year, "is a not leap year")
        else:
            print(year, "is a leap year")
    else:
        print(year, "is a not leap year")

    Output 1:

    Enter the Year: 2020
    2020 is a leap year

    Output 2:

    Enter the Year: 2019
    2019 is a not leap year

    Conclusion

    Here in this tutorial, you learned how to write a python program to check if the user entered Year is a leap year or not. In the first check, we check if the year is divisible by 4. If the Year is divisible by 4 and not divisible by 100 then it is a leap year. If a Year is divisible by 4 and 100, it has to be divisible by 400 to be a leap year.

    People are also reading:

    Leave a Comment on this Post

    0 Comments