Challenge
Summary function
…the ones where the sensor sent nothing. Write one function that returns the whole summary, then make it safe for an empty pass. Four numbers in one dict Write summarise(readings) , which returns a…
Showing 11–20 of 86
Challenge
…the ones where the sensor sent nothing. Write one function that returns the whole summary, then make it safe for an empty pass. Four numbers in one dict Write summarise(readings) , which returns a…
Challenge
…Read it from the bottom up to find the error, the function and the line, fix the bug there, then follow a longer traceback through four calls to a second bug.
Challenge
…statuses give None, make every path return, then write a function where every path returns.
Example
Return can be used to exit function early when a condition is met.
Challenge
Extend format_log() from "Log formatter function" with **fields, so any extra keyword arguments are added to the line as key=value pairs, then pass whole dicts of fields into it with ** at the call.
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
Sort launches by date with sorted() and a small function that returns each launch's date, then sort the cargo manifest heaviest first with a key function and reverse=True.
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.
Example
Functions can return complex data structures like dictionaries or lists.