English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
In this program, you will learn to check if a year is a leap year. We will use nested if ... else to solve this problem.
To understand this example, you should understand the followingPython programmingTopic:
Leap years can be4divisible, except for centennial years (years ending in 00). Only those that can be completely4Leap years are exactly divisible by 00, for example,
2017 Is not a leap year 1900 is not a leap year 2012 Leap year 2000 is a leap year
# Python program to check if a year is a leap year year = 2000 # Get year from user (integer input) # year = int(input("Enter year: ")) if (year % 4) == 0: if (year % 100) == 0: if (year % 400) == 0: print("{0} is a leap year".format(year)) else: print("{0} is not a leap year".format(year)) else: print("{0} is a leap year".format(year)) else: print("{0} is not a leap year".format(year))
Output result
2000 is a leap year
You can change the value of the year in the source code, then run the program again to test it.