Space Python Loading Python…

Early Exit from Function

 
0:00 / 0:00

Challenge

Practise what this example shows with these challenges.

Silent branch

Fix the codeEasy 3 stages

status_light() returns None for Scrub because that branch sets a variable but never returns it. Predict the last line, find which statuses give None, make every path return, then write a function where every path returns.

Start the challenge

Test the alert levels

Write the codeMedium 2 stages

Write assert checks for alert_level(): one temperature for each level first, then the values exactly on each threshold and just below them, so a > written instead of >= can't slip through.

Start the challenge

Guard clauses

Fix the codeMedium 2 stages

Rewrite the four nested ifs in can_dock() as guard clauses that return a reason as soon as a check fails, keeping every answer the same, then add a new docking rule as one more guard with a default parameter.

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