Lab, Lists, Tuples and Strings
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.
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 tuple book holding "Matilda", "Roald Dahl" and 1988. Unpack it into title, author and year, then print Matilda by Roald Dahl (1988).
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 each ___ so the program prints the winner, the last place and everyone in between: Winner: Ana, Last: Eve, Middle: ['Bo', 'Cy', 'Dan'].
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.
This program tries to change the day in a date tuple and crashes. Fix it by building a new tuple, so it prints (2024, 6, 16). Keep date a tuple.
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 a, b and c each time any of them changes, once all three exist.
a, b, c = 1, 2, 3 a, b, c = b, c, a a, b = b, a c = a + b
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: Unpack the tuple once instead of indexing it.
This program reads each part of size by index. Rewrite it to unpack size into width and height in one line, with no square-bracket indexing. 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.
Each team is a (name, points) tuple. Print the teams from most to fewest points, numbered, then print the total points. Use unpacking, and sort by building (points, name) tuples. The output is:
1. Owls 42 2. Foxes 38 3. Bees 31 Total: 111
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.