Lab, Functional Tools and Modules
7 tasks, easy to hard: Predict, then run, Write it, Complete it, Fix it, Trace it, Refactor it, Mini challenge. Hints come one at a time and you can see each answer. Lab work is saved as practice and earns no XP.
Open the lessonYou can read every task below. Running, checking and saving them needs a free ID.
7 tasks
Task 01 .Type what the program will print, then run it to compare.
Type exactly what this program prints. One comprehension filters, the other chooses a value for every item.
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.
Task 02 .Solve it from the prompt, starting from an empty editor.
Given words = ["sun", "planet", "star"], build lengths, a list of each word's length, with a list comprehension and print it.
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.
Task 03 .Fill the marked gaps in the starter code.
Replace ___ so stock maps each fruit name to its quantity, then the program prints the dictionary and the quantity of plums.
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.
Task 04 .The starter code has a bug. Repair it so the checks pass.
The program should replace negative readings with 0 and keep the rest, printing [4, 0, 9, 0]. It has a syntax error. Fix it.
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.
Task 05 .Fill the table with the variable values, step by step.
This loop does what [n * 2 for n in nums if n % 2 == 1] does. Each row shows n and result each time one of them changes, once both exist.
nums = [1, 2, 3, 4, 5]
result = []
for n in nums:
if n % 2 == 1:
result.append(n * 2)Sign in or create a free ID to fill in and check this table.
Task 06 .Rewrite working code to the stated rule, keeping the same output. Rule: Build evens with one list comprehension: no for statement and no append.
This code works. Rewrite it so evens is built by one list comprehension, with the same output.
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.
Task 07 .A short task that combines this lesson with earlier ones.
Each order is (customer, item, amount). Using comprehensions, print three lines: the amounts over 20 as a list, a dictionary from customer to their total spend (customers in alphabetical order), and the sorted distinct items. The output should be:
[25, 40]
{'Ana': 45, 'Ben': 22, 'Cy': 40}
['book', 'lamp', 'pen']Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and save your practice. Practice does not award XP.