Quiz
Python Return Values Quiz
Free beginner quiz on Python return values: 15 questions on return, None, several values, lists, dictionaries and early exit. Instant answers.
Showing 1–10 of 78
Quiz
Free beginner quiz on Python return values: 15 questions on return, None, several values, lists, dictionaries and early exit. Instant answers.
Example
Return statement returns a value from function. Function can perform calculations and give result.
Challenge
to_kelvin() prints its result instead of returning it, so the caller gets None. Predict the last line, find out what the function gives back, fix it with return, then write a conversion function that…
Example
Function can return multiple values as a tuple. Unpacking on assignment.
Example
Functions can return complex data structures like dictionaries or lists.
Quiz
…beginner quiz on Python functions: 15 questions on def, return, arguments, default values, *args, scope and docstrings. Instant answers.
Challenge
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…
Challenge
…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.
Challenge
Write summarise(readings), which returns the count, min, max and mean of a list of readings as one dict, then make it handle a pass with no data and round the mean, so any program can use the summary.
Challenge
…the name as local, fix it by passing the count in and returning the new one, then write a fuel function the same way.