+ 2

Me ayudan con esto?

No debería imprimir 'Si'? Porque pasa esto? if (1 or 0) <= 0: print("Si") else: print("No") Output: No

30th Apr 2020, 10:58 PM
Orking20
Orking20 - avatar
5 odpowiedzi
+ 2
The (1 or 0) condition turns into a boolean expression where the first value (number 1) is evaluated as true. So the if-statement becomes: if (1 <= 0) which is false and it enters the else branch. A logical AND would evaluate to true if both conditions are met, but to check both the 1 and the 0 you'd have to change the grouping of those the values into separate conditions since (1 and 0) as a boolean expression will always be false. To check both numbers you could use: if 1 <= 0 and 0 <= 0:
1st May 2020, 12:11 AM
Damyian G
Damyian G - avatar
+ 1
Pero si ahí ponés: if (2 or 0) <= 1: print("Si') else: print("No") Output: No Pareciera que el or está funcionando como un and
30th Apr 2020, 11:47 PM
Orking20
Orking20 - avatar
+ 1
Si 1 = 1 y 0 < 1, mientras que 2 es mayor que 1
30th Apr 2020, 11:56 PM
BroFar
BroFar - avatar
+ 1
Thank you! I understand now
1st May 2020, 12:28 AM
Orking20
Orking20 - avatar