Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    Python Program to Check Leap Year

    Python Programming Examples


    This Python program does leap year checks. It takes input from the user in the form of integers and performs simple arithmetic operations within the condition statement for the output.

    Program:

    #Variable definition and assignment
    year = 2024
    
    #Remove comments from the bottom line to take input from the user
    #year = int(input("Enter a year: "))
    
    #It is a centenary year if the value is divisible by 100 with no remainder.
    #Centenary year is a leap year divided by 400
    if (year % 400 == 0) and (year % 100 == 0):
        print("{0} is a leap year".format(year))
    
    #If it is not divisible by 100 then it is not a centenary year
    #A year divisible by 4 is a leap year
    elif (year % 4 ==0) and (year % 100 != 0):
        print("{0} is a leap year.".format(year))
    
    #If the Year is not divisible by both 400 (centenary year) and 4 (centenary year) then:
    #The Year is not a leap year
    else:
        print("{0} is not a leap year.".format(year))

    Program Output:

    2024 is a leap year.


    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.