Todos los ejemplos

Ejemplos

Encuentra el error en dos líneas de Python

Un bucle for sin los dos puntos: el error encontrado, por qué Python se detiene antes de imprimir nada y luego la línea corregida.

  • 0:45
  • Problemas de código
  • Narrado por Erinome
  • Inglés

Hecho a partir de un prompt

Find the error: for i in range(5) print(i)

Transcripción del video

In this video, we find and fix a Python syntax error.

Question one. Find the error: The first line reads for i in range, with five in parentheses. The indented second line reads print, with i in parentheses.

Notice that line one is missing a colon after the closing parenthesis. Python requires a colon at the end of a for loop header. Without it, Python raises a SyntaxError before either line executes, so nothing is printed.

The indentation of print is correct and does not need changing. Hence, the corrected first line is for i in range, open parenthesis, five, close parenthesis, colon.

Tu tema, dibujado en un minuto, más o menos.

Tus primeros 2 videos son gratis, de hasta 1 minuto cada uno, con marca de agua. No necesitas tarjeta. Producto completo, con todas las voces y estilos incluidos.