Article 6KPVW Please tell the error in code below, as seems as perfectly fine as it's alternative.

Please tell the error in code below, as seems as perfectly fine as it's alternative.

by
ajiten
from LinuxQuestions.org on (#6KPVW)
Please tell why the below code is considered incorrect?

Code:def is_leap(year):
leap = False

# Write your logic here
if year%400==0 :
leap = True
elif year%4 == 0 and year%100 != 0:
leap = True
return leap

year = int(input())
print(is_leap(year))If asked for, can provide link of where it has been marked as incorrect.

The alternative provided is :
Code:def is_leap(year):
leap = False

if (year % 4 == 0) and (year % 100 != 0):
# Note that in your code the condition will be true if it is not..
leap = True
elif (year % 100 == 0) and (year % 400 != 0):
leap = False
elif (year % 400 == 0):
# For some reason here you had False twice
leap = True
else:
leap = False

return leapBut, I see nothing gained, except redundant code.

Also, ran the stated (earlier) code, and gives correct results.
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments