Check a Leap Year
Divisibility rules aur boolean operators se Gregorian leap year check karo.
Working code
year = 2024
is_leap = year % 400 == 0 or (year % 4 == 0 and year % 100 != 0)
if is_leap:
print("Leap year")
else:
print("Not a leap year")Expected output
Leap yearHow it works
400 se divisible year leap hota hai. Otherwise year ko 4 se divisible aur 100 se not divisible hona chahiye.
Try Yourself
year = 2100
is_leap = year % 400 == 0 or (year % 4 == 0 and year % 100 != 0)
print(is_leap)