Challenge
Test the alert levels
The engine alert check from "Alert level" is now a function, alert_level() , and other programs depend on it. Before anyone changes it again, it needs tests: small checks that run in a second and…
Showing 11–20 of 39
Challenge
The engine alert check from "Alert level" is now a function, alert_level() , and other programs depend on it. Before anyone changes it again, it needs tests: small checks that run in a second and…
Challenge
…caller gets None. Predict the last line, find out what the function gives back, fix it with return, then write a conversion function that returns.
Challenge
…parameters and return value; the tests read both from the function itself.
Challenge
…and lists with negative values, so broken copies of the function can't pass.
Challenge
…noticed until the fuel budget came out 62.5 kg short. A function that gets a value it can't work with should say so, loudly and clearly, at the moment it happens. Raise ValueError Make fuel_needed()…
Challenge
…pass from the database, sometimes just two numbers. A function that wants a list makes every one of those calls a little clumsier than it needs to be. Write an average that takes the values as they…
Challenge
…where waiting is worse than failing. Give the uplink function sensible defaults, then add an option without touching any of its callers. Defaults Give retries a default of 3 and timeout a default of…
Challenge
refuel() assigns to fuel_kg inside the function, creating a local variable and leaving the global fuel unchanged. Predict the last line, compare both values, fix it by returning the total, then write…
Challenge
…find out how the preview reached the stored list, fix the function, then write another one that leaves its input alone. Predict and run Don't run the code yet. Read it and decide what it will print on…
Challenge
The docking computer decides whether the ship may dock. Its function has grown one condition at a time, each inside the last, and the reason for a refusal now sits four levels deep, at the far end of…