Alle Beispiele

Beispiele

Finde den Fehler in zwei Zeilen Python

Einer for-Schleife fehlt der Doppelpunkt: der Fehler gefunden, warum Python schon vor jeder Ausgabe abbricht, dann die korrigierte Zeile.

  • 0:45
  • Code-Aufgaben
  • Gesprochen von Erinome
  • Englisch

Aus einem Prompt erstellt

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

Transkript zum 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.

Dein Thema, gezeichnet in etwa einer Minute.

Deine ersten 2 Videos sind kostenlos, je bis zu 1 Minute lang, mit Wasserzeichen. Keine Kreditkarte nötig. Das komplette Produkt, inklusive aller Stimmen und Stile.