Bottom Page

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
Quote
#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.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote
#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
Quote
#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

Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Facing issue with pyautogui program after PC upgrade Utkarsh29 2 530 Jul-15-2019, 05:20 PM
Last Post: Utkarsh29
  Creating folders dynamically with year/month/date sritsv 0 2,853 Oct-16-2017, 03:44 PM
Last Post: sritsv
  Calculating what year it is when you are 100 years old dankim9000 2 5,352 Apr-26-2017, 08:03 PM
Last Post: dankim9000
  Leap Year MartinEvtimov 14 11,400 Mar-10-2017, 01:46 AM
Last Post: Larz60+
  Logic to convert an integer to YEAR / MONTH hugobaur 9 2,990 Oct-18-2016, 11:58 AM
Last Post: hugobaur

Forum Jump:


Users browsing this thread: 1 Guest(s)