We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

I thought the constraints meant that you could write your code assuming the constraints to be true - that no test cases would include inputs that don't satisfy the constraints.

Reversing the order almost works, but you have to add an else block returning False at the end to capture cases where none of the if blocks execute (like for the year 1992) and also change all elif statements to if statements. I.e:

Why wouldn't 1992 return true if % 4 == 0 is the first statement? it divides cleanly by 4 with no remainder, yet it gives false in the original scenario.

## Write a function

You are viewing a single comment's thread. Return to all comments →

This is what i did.

Thanks for explaining

the first if statement if year%4==0: return True this will give true for 1900 year also but that it is not true

you have to give the constraint like

if year in range(1900,pow(10,5)+1): because they clearly mentioned this constraintr

I thought the constraints meant that you could write your code assuming the constraints to be true - that no test cases would include inputs that don't satisfy the constraints.

that is true

You can just reverse the order and it will be fine.

Reversing the order almost works, but you have to add an

`else`

block returning`False`

at the end to capture cases where none of the`if`

blocks execute (like for the year 1992) and also change all`elif`

statements to`if`

statements. I.e:This passes all the test cases.

i will mark your words

not passes year %100 == 0 test

Why wouldn't 1992 return true if % 4 == 0 is the first statement? it divides cleanly by 4 with no remainder, yet it gives false in the original scenario.

true

I reversed the order and it passed all the tests. But i dont know why it did. what did the reversing the order do??

Took a few tries before I understood the conditions but I got it!

Here's my solution:

That wound up failing two test cases.

how can you return heap without any function

This quote

isthe function. The post doesn't include the declaration because it's not relevant.fail in two cases

What about trying something like this:

this works for all test cases

It fails for the year 2100

It is giving runtime error

def is_leap(year): leap = False if year % 4 == 0: leap = True if year % 100 == 0: leap = False if year % 400 == 0: leap = True return leap

make the last loop as elif year%100!=0: return True

this will work for all the cases

Good Work ！ I think I ignored the "unliess" in the problem sheet. I learned the if and elif, but never used them. This is an interesting question.

This is what I did.

year = int(input())

def is_leap(year): leap = False if year%4==0: leap=True elif year%100==0 and year%400==0: leap=True else: leap=False return leap

year = int(input()) print(is_leap(year))

why it is giving error on input 2100

ran your code, 3 out of 6 test cases failed :(

ohh ... halo