Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

How to Check Leap Year using Python?

How  to Check Leap Year using Python?                                                


1 Answer
Jayashree

Leap year comes after every four years. For normal year, if it is divisible by four, it is called leap year, whereas for century year, it should be divisible by 400. The following Python program shows whether the year is leap or not

yr=int(input('enter year'))
if yr%100==0: #century year
       if yr%400==0:
           print ('{} is leap year'.format(yr))
       else:
          print ('{} is not leap year'.format(yr))
else:
       if yr%4==0:
          print ('{} is leap year'.format(yr))
else:
         print ('{} is not leap year'.format(yr))

Sample Output:

enter year2012
2012 is leap year

enter year2018
2018 is not leap year

2000 is leap year

enter year1900
1900 is not leap year
Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.