All examples

Examples

Find the error in two lines of Python

A for loop missing its colon: the error found, why Python stops before printing anything, then the corrected line.

  • 0:45
  • Code problems
  • Narrated by Erinome
  • English

Made from a prompt

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

Video transcript

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.

Your topic, drawn in about a minute.

Your first 2 videos are free, up to 1 minute each, watermarked. No card required. Full product, every voice and style included.