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, then run it to compare.
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 list shopping with "apples" and "bread". Append "cheese", insert "milk" at the front, then print the list and its length on two lines:
['milk', 'apples', 'bread', 'cheese']4
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 ___ with a slice so the program prints the first three days, the last two days, and every other day.
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 should print Last score: 92 but stops with an error. Fix the indexing.
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 stack and top each time either changes, once both exist. Write lists the way Python prints them.
stack = [5] top = 0 stack.append(8) stack.append(2) top = stack.pop() stack.insert(0, top) top = stack[-1]
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: Use sorted() to get a sorted copy instead of .copy() and .sort().
This program copies the list and sorts the copy so the original stays in order. Rewrite it with sorted() in one line, without .copy() or .sort(). 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.
The list marks = [62, 48, 91, 75, 48, 83] holds test marks. Without changing marks, print:
Highest: 91Lowest: 48Passed: 4 (a pass is 50 or more)Top two: [91, 83]Unchanged: [62, 48, 91, 75, 48, 83]
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.