Space Python Loading Python…

Read the traceback

Fix the codeEasy 2 stages

The engine temperature report stopped working after a tidy-up. Python didn't just give up, though: it printed a traceback, a short report of where the program was when it failed.

Read it, note what it tells you, and fix the bug exactly where it points.

Run the program. In the console, Python prints the traceback:

File "script.py", line 20
File "script.py", line 16, in average_kelvin
File "script.py", line 10, in to_kelvin
KeyError: 'temperature_c'

Read it from the bottom: the last line is the error, and the File line just above it is where it happened. Fill in error_type, crash_function and crash_line at the end of the program, then fix the bug on that line so the program prints:

Average: 695.0 K

Fix the function, not the data: the readings come from the sensors as they are.

Read the traceback
Fix it where it failed

Finish stage 1 to unlock this stage.

The report now covers each pass, and the newest export sends one temperature as text. Pass 1 prints, then the program stops with a longer traceback. Count its File lines into frames, store the error's name in error_type, and fix the bug on the line the lowest File line names, so it prints:

Pass 1: 695.0 K
Pass 2: 695.7 K

The data stays as it is: make the function accept a temperature sent as text.

Read the longer traceback
Fix it where it failed
You're not logged in, so your progress is kept in this browser only. Log in to save it, and to use hints and solutions.

Hints

script.py
PythonLn 1, Col 1Spaces: 4
Loading the Python environment…

Separate arguments with commas. They're passed on every Run as sys.argv[1:].