0

What's wrong with this code

23.2

1st Mar 2022, 8:20 AM
Askar Kondybaev
Askar Kondybaev - avatar
8 odpowiedzi
+ 3
G'day olli you were doing it different to everyone else, but not entirely wrong.... I like it! Your first if eliminates all the years that aren't evenly divisible by 4, great idea.✅ Your next 2 elifs are in the wrong order, and one of them needs to say is a "leap year" with the other staying "not a leap year". They also need to be the more usual way, eg 👍elif year%400==0: Your logic: eliminates the "not divisible by 4" then it needs to approve the divisible by 400, then eliminate the divisible by 100, then anything that passed all of those must be approved "a leap year". Don't change your cool idea, just adjust your logic 😎 https://code.sololearn.com/cMnAF0MSp3FX/?ref=app
1st Mar 2022, 10:54 AM
HungryTradie
HungryTradie - avatar
+ 3
olli import calendar print("Leap year" if calendar.isleap(int(input()) else "Not a leap year") learning the basics is great, but learning the modules is also a good idea.
3rd Mar 2022, 7:05 AM
Bob_Li
Bob_Li - avatar
+ 2
olli Without having access to the challenge description, we can only guess. But I would guess this is a code to find leap years. You might wish to review your understanding of % and play with the following concept if year %4 ==0:
1st Mar 2022, 8:58 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
# Logic: for finding the leap year, you need to first find that the given year is a century year (like 1900, 1800, 2000) or a non century year (like 2001, 2016, 2005, 2012) # century year is leap if it comes in every 400 years # similarly a non century year is leap if it comes in every 4 years # if it is a century year then it means it should be divisible by 400 (necessary condition) to be a leap year # if it is non century year then it means it should be divisible by 4 and not divisible by 100. example 1900 is divisible by 100. So not a leap year https://code.sololearn.com/cBm31AI8C7vd/?ref=app
1st Mar 2022, 9:29 AM
NonStop CODING
NonStop CODING - avatar
1st Mar 2022, 10:36 AM
SoloProg
SoloProg - avatar
0
year = int(input()) if year % 4 > 0: print ("Not a leap year") elif year % 100 > 0: print ("Not a leap year") elif year % 400 > 0: print ("Not a leap year") else: print ("Leap year")
1st Mar 2022, 8:20 AM
Askar Kondybaev
Askar Kondybaev - avatar
0
You code is not working because you have designed it for only century years like 2000, 2100, 1900 You did not designed it for non century year like 2016, 2005, 2001 so your code is showing wrong answer when a non century year is entered.
1st Mar 2022, 9:34 AM
NonStop CODING
NonStop CODING - avatar