You are viewing a single comment's thread. Return to all comments →
You can write it without parentheses like this:
return year % 4 == 0 and year % 100 != 0 or year % 400 == 0
Adding parenthesis increases readability. I might be wrong though!
what is the logic of this.....man!!!!
here, the return statement returns in boolean. where the given conditions in the problem are put.a year is a leap year if it is divisible by 4 and 400 but not divisible by 100.
You may find the logic here.
Thanks for this , this page cleared everything about Leap years !
leap = False
elif year%100==0 and year%400==0:
year = int(input())
why it is giving error on input 2100
But then how does python know which one you mean:
1.y%4 AND y%100, or y%400
2.y%4, and y%100 OR y%400?
That's like saying these sentences state the same thing:
1.I will eat pie and roaches, or I will eat pasta.
2.I will eat pie, and either I will eat roaches or pasta.
Am I missing something?
Just like there is order of operations for mathematical operators, there is precedence for Python operators. AND has higher precedence than OR, so it is evaluated first.
Order of precedence: NOT > AND > OR
Thanks for this. I was having issues with If/ else statements.
plss explain this a bit clear
how return works their
here solving the given condition, return turns true
can you please explain the code.
I think this is a good read, to understand the logic of a leap year. The code is straight forward.