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 26
Quiz
Free beginner quiz on Python return values: 15 questions on return, None, several values, lists, dictionaries and early exit. Instant answers.
Challenge
crew = crew.sort() leaves the roster as None. Predict it, find out what sort() really gives back, fix it by sorting in place, then sort readings from highest to lowest and keep the top three.
Challenge
…parser from "Line to record" into parse_line(line), which returns the record dict, then let it return None for blank, comment and damaged lines so the loop only keeps real records.
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…
Challenge
…then add a keyword-only decimals option after *values and return None when there are no values.
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
…function": the whole record for a good line first, then None for a blank line, a comment and a line with a missing field, so a broken parser can't pass.
Challenge
…Predict it, prove the calls share one list, fix it with None as the default, then write a function that hands out a fresh list each time.
Challenge
…first, then the edge cases, an empty list that should give None and lists with negative values, so broken copies of the function can't pass.
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.