Example
Returning Dictionary or List
Functions can return complex data structures like dictionaries or lists.
Showing 21–30 of 86
Example
Functions can return complex data structures like dictionaries or lists.
Challenge
…the count in and returning the new one, then write a fuel function the same way.
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.
Example
Function can return multiple values as a tuple. Unpacking on assignment.
Example
Combining regular parameters, *args and **kwargs in one function.
Example
…between positional and keyword arguments. Flexible function calling.
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()…