This python program allows the user to enter any year and then it will check whether the user entered year is Leap year or not using the If statement. First condition (year%400 == 0) will check whether the (year%400) reminder is exactly equal to 0 or not.
![]() |
Python Program to Check Leap Year or Not | Codeing School |
Source Code: Python Program to Check Leap Year or not
# check leap year or not
x = int(input("enter a year: "))
if(x%400 == 0):
print("This is leap year")
else:
if (x%4 == 0 and x%100 != 0):
print("This is a leap year")
else:
print("This is not leap year")
Output:
2004 is a leap year
You can change the value of year in the source code and run it again to test this program.
0 comments:
Post a Comment