Space Python Loading Python…

Creating Simple Functions

 
0:00 / 0:00

Challenge

Practise what this example shows with these challenges.

Log formatter function

Fix the codeEasy 2 stages

Move the mission log's f-string into format_log(t, level, msg), a function that returns the line instead of printing it, then fix the alignment of every log line with one change inside the function.

Start the challenge

Extract a function

Fix the codeEasy 2 stages

Move a 3D distance calculation that is copied for three waypoints into distance_km(a, b), keeping the output exactly the same, then put the waypoints in a dict and find the nearest one with the same function.

Start the challenge

Legacy script

Fix the codeHard 2 stages

A 70-line engine report repeats the same twelve lines for each engine. Restructure it into parse_feed() and summary_line() with the output unchanged to the character, then add assert tests that would catch either function breaking.

Start the challenge

Discussion

Stuck on this example or want to go further? Ask here, or see what others asked.

Log in to ask and reply.

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:].