A leap year is a year that is evenly divisible by 4, except for years that are divisible by 100. However, years divisible by 400 are leap years again.
Method 1
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
print("Leap year")
else:
print("Not leap year")
else:
print("Leap year")
else:
print("Not leap year")
Method 2:
Method 3:
year = int(input("Enter a year: "))
if year % 400 == 0:
result = "Leap year"
elif year % 100 == 0:
result = "Not leap year"
elif year % 4 == 0:
result = "Leap year"
else:
result = "Not leap year"
print(result)
0 Comments