Challenge
Missing index
readings[5] on a list of five readings stops with an IndexError. Predict it, work out the valid indexes with len(), fix it with [-1], then print the first, middle and last readings for any length.
Showing 31–40 of 92
Challenge
readings[5] on a list of five readings stops with an IndexError. Predict it, work out the valid indexes with len(), fix it with [-1], then print the first, middle and last readings for any length.
Challenge
Write assert checks for mean(): an ordinary list and a list with one value first, then the edge cases, an empty list that should give None and lists with negative values, so broken copies of the…
Challenge
…the rota, and check its own work. In turn Build rota , a list of (day, shift, name) tuples for every shift of the week, in order, taking the crew in turn. Print one line per day, then count how many…
Challenge
…unpacked. The loading supervisor doesn't want to read both lists side by side: she wants to know what changed. Work out what was added and what was removed, then how much stayed the same. Added and…
Challenge
Write problems(item), which lists everything wrong with one cargo item: missing fields, a mass that isn't a number, is 0 or is over the limit. Print a pass or fail line per item, then catch duplicate…
Quiz
Free beginner quiz on Python for loops: 15 questions on lists, strings, range(), enumerate(), totals and break, with instant answers.
Quiz
…values: 15 questions on return, None, several values, lists, dictionaries and early exit. Instant answers.
Quiz
…20 multiple-choice questions on print(), strings, lists, dictionaries, loops and functions, with instant answers.
Example
Tuples are immutable lists. Once created, they cannot be modified.
Challenge
Merge three pages of launch results into one list with extend(), then fetch page after page in a while loop and stop at the first short page, the way paginated API responses are read.