Reading an error message
Why it matters You will see hundreds of errors in this course. Reading them in ten seconds, instead of guessing, is a skill worth hours.
A Python error ends with a traceback. Read it from the bottom up:
- The last line names the kind of error and says what went wrong, for example
ZeroDivisionError: division by zero. - The line above it shows the exact line of your code that failed, with its line number.
- Lines further up show who called that function, if you need the path that led there.
See it
Traceback (most recent call last):
File "lesson.py", line 6, in <module>
print(average_pace([5, 10], []))
File "lesson.py", line 2, in average_pace
return sum(times) / len(times)
ZeroDivisionError: division by zero
Bottom line: dividing by zero. One up: line 2, len(times) was 0. So the function was handed an empty list and has no plan for it.
Traceback: the trail Python prints when it stops, newest step at the bottom.
Recap Bottom line for what, the line above for where.
The starter code crashes. Run it, read the traceback, and fix the function so that:
average_pace(distances, times)returns total time divided by total distance (minutes per km).- If the total distance is 0, it returns
Noneinstead of crashing.
Also set error_kind to the name of the error you saw, as a string.
Spotted a problem in this lesson? Report it · Ask about this lesson
This exercise opens soon
Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.
This browser is blocking cookies for learn.floati.life, so lessons you finished here cannot open in order. Allow cookies for this site and reload.