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. The key decides what is compared; ties keep their original order.
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.
Create a lambda that returns a number squared and store it in square. Print square(7) and square(12) on separate lines.
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 ___ with a key so the people are sorted from youngest to oldest.
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 print [2, 4, 6] twice, once directly and once after counting. Fix it so the values can be used more than once.
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.
Each row shows item, qty and total each time one of them changes, once all three exist.
items = ["pen", "pad", "ink"]
qtys = [3, 1, 2]
total = 0
for item, qty in zip(items, qtys):
total = total + qtySign 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 passed with filter and a lambda: no for loop and no append.
This code works. Rewrite it so passed is built with filter and a lambda, without a for loop or append. The output must not change.
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.
Two lists hold player names and goals. Using zip, sorted with a key, and any, print the players from most to fewest goals as name: goals, then print Hat-trick: True or Hat-trick: False depending on whether anyone scored 3 or more. The output should be:
Lu: 4 Ami: 2 Jo: 1 Hat-trick: True
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.