Python Forum

Full Version: leap year program issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

Can someone please help with the following program.

Can't seem to figure out where I am going wrong.

My program executes fine, just ends up giving the wrong result. Ex. 1992 is a leap year, but my program shows it's not.

a = int(input("Enter year : "))

if (a % 4) == 0:

   if (a % 100) == 0:

       if (a % 400) == 0:

           print("Tis is leeap year")

       else:

           print("not a leap year")

   else:

       print("not a leapp year")

else:

   print("No it ain't")
TIA
the logic looks wrong to me. the 100 year test is supposed to be different than the 400 year test. but yours are coded alike.
Hello!
How about calendar.leap?

>>> import calendar

>>> calendar.isleap(1992)
True
Line 17 is wrong (the one with 'leapp'). That line is only triggered if the year is divisible by 4, but it says that the year is not a leap year. Also, it would be clearer if you called your variable 'year' rather than 'a'.