leap year program issue - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: leap year program issue (/thread-1916.html) |
leap year program issue - jashajmera - Feb-04-2017 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 RE: leap year program issue - Skaperen - Feb-04-2017 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. RE: leap year program issue - wavic - Feb-04-2017 Hello! How about calendar.leap? >>> import calendar >>> calendar.isleap(1992) True RE: leap year program issue - ichabod801 - Feb-04-2017 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'. |