Easy Tutorial
❮ Ref Math Sinh Python Func Chr ❯

Python Leap Year Check

Python3 Examples

The following example is used to determine if the year entered by the user is a leap year:

Example (Python 3.0+)

# -*- coding: UTF-8 -*-

# Filename : test.py
# author by : www.tutorialpro.org

year = int(input("Enter a year: "))
if (year % 4) == 0:
   if (year % 100) == 0:
       if (year % 400) == 0:
           print("{0} is a leap year".format(year))   # A century year divisible by 400 is a leap year
       else:
           print("{0} is not a leap year".format(year))
   else:
       print("{0} is a leap year".format(year))       # A non-century year divisible by 4 is a leap year
else:
   print("{0} is not a leap year".format(year))

We can also use an embedded if statement to achieve this:

Executing the above code will produce the following output:

Enter a year: 2000
2000 is a leap year
Enter a year: 2011
2011 is not a leap year

Python3 Examples

❮ Ref Math Sinh Python Func Chr ❯