Write a program to Check Leap Year in Python
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # Python program to check if the input year is a leap year or not 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)) 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)) |
This Python program takes an input year from the user and determines if it is a leap year or not. A leap year is a year that is divisible by 4, except for end-of-century years, which must be divisible by 400 to be leap years.
The program starts by asking the user to input a year. The input is then stored as an integer in the variable “year”.
Then, the program checks if the year is divisible by 4. If it is divisible by 4, it checks if the year is divisible by 100. If it is also divisible by 100, it checks if it is divisible by 400. If it is divisible by 400, it prints “year is a leap year” to the output, where year is the input provided by the user. If it is not divisible by 400, it prints “year is not a leap year” to the output.
If the year is not divisible by 100, the program prints “year is a leap year” to the output.
If the year is not divisible by 4, the program prints “year is not a leap year” to the output.
The output will be a string indicating whether the input year is a leap year or not.