+ 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
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:
+ 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
+ 1
Si 1 = 1 y 0 < 1, mientras que 2 es mayor que 1
+ 1
Thank you! I understand now