Ibuprofeno.py馃拪| #113: Explica este c贸digo Python

Cristian Fernando - May 29 - - Dev Community

Explica este c贸digo Python

Dificultad: F谩cil

print(not True * (100 + True))
Enter fullscreen mode Exit fullscreen mode

馃憠 A. 101
馃憠 B. 0
馃憠 C. 100True
馃憠 D. SyntaxError


Respuesta:

馃憠 B. 0

Ya sabemos que True infiere a 1 y False infiere a 0.

Entonces es posible hacer operaciones aritm茅ticas con booleanos.

Vamos por partes:

  • not True equivale a False, que en numeros equivale a 0.
  • 100 + True equivale a 101 porque True es 1.
  • Finalmente tendr铆amos 0 * 101 que nos da 0

En este ejercicio en concreto basta con saber que not True da 0 para inferir que el resultado total ser谩 0 (todo n煤mero multiplicado por 0 ser谩 0 ya que el 0 es neutro multiplicativo)

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player