In this post, we will make a python program to check whether the given year is a leap year.
Leap Year: One year in every four has 366 days [February has 29 days instead of 28]. The reason why we have leap years is really fascinating, this video does more justice: Video Link
Algorithm:If one of the following conditions is satisfied then the given year is a leap year.
- Every year that is divisible by 4 and not divisible by 100.
- A year that is divisible by 4 and also divisible by 400.
Leap Year Program in Python using if-else
year = int(input("Which year do you want to check? ")) if (year%4==0 and year%100!=0) or (year%4==0 and year%400==0): print("Leap year.") else: print("Not leap year.")
Which year do you want to check? 2022
Not leap year.
leap year program in python hackerrank solution
def is_leap(year): leap = False # Write your logic here if (year%4==0 and year%100!=0) or (year%4==0 and year%400==0): leap=True return leap year = int(input()) print(is_leap(year))