How to Judge Leap Years in Python


Here we can see how to judge the leap year in Python.

Source Code


#! /usr/bin/env python3
# -*- coding: utf-8 -*-

year = int(input("Please enter the year: "))

if (year % 4) == 0:
    if (year % 100) == 0:
        if (year % 400) == 0:
            print('The year of %d is leap year' % year)
        else:
            print('The year of %d is not leap year' % year) 
    else:
        print('The year of %d is leap year' % year)
else:
    print('The year of %d is not leap year' % year) 

Output:


Please enter the year: 1900
The year of 1900 is not a leap year

Please enter the year: 2000
The year of 2000 is a leap year

Please enter the year: 1995
The year of 1995 is not a leap year

Please enter the year: 1996
The year of 1996 is a leap year
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments