Challenge
Any number of values
…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…
Showing 31–40 of 86
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…
Challenge
…one list, fix it with None as the default, then write a function that hands out a fresh list each time.
Challenge
…with it, not just the first problem. Write the check as a function that collects the problems, then add a rule for the ID format. Missing fields and negative mass Write validate_cargo(item) , which…
Example
Operator * allows accepting any number of positional arguments.
Example
Parameters can have default values. Used when argument is not provided.
Challenge
…it stays fixed? Six months from now someone will tidy the function, and log=[] looks so much simpler than the None check. Write the test that proves the fix: it has to pass now and fail on the old…