Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
leap year program issue
#1
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
Reply
#2
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#3
Hello!
How about calendar.leap?

>>> import calendar

>>> calendar.isleap(1992)
True
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#4
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'.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to get year not the entire year & time mbrown009 2 862 Jan-09-2023, 01:46 PM
Last Post: snippsat
  Problem with module time and leap seconds Pedroski55 3 1,189 Oct-07-2022, 11:27 PM
Last Post: Pedroski55
  Issue with program not passing to other elif condition Abdirahman 6 2,060 Nov-21-2021, 07:04 AM
Last Post: Abdirahman
Photo Algorithm for leap year (structogramm coder_sw99 3 2,192 Jul-23-2021, 02:13 PM
Last Post: DeaD_EyE
  Leap Year Issue spalisetty06 3 2,173 Jul-02-2020, 03:29 PM
Last Post: bowlofred
  Facing issue with pyautogui program after PC upgrade Utkarsh29 2 2,911 Jul-15-2019, 05:20 PM
Last Post: Utkarsh29
  Leap Year MartinEvtimov 14 24,945 Mar-10-2017, 01:46 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020