Lab, Standard Library Tools
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. Because the seed is reset, the second list repeats the first.
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.
Set the seed to 3, then build rolls, a list of 10 dice rolls with random.randint(1, 6). Print the list and its total.
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 team holds 3 different players chosen at random.
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 shuffle the cards and still have all five, printing 5 and True. It crashes because the deck becomes None. 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.
A counter moves up or down by one on each step, chosen by a seeded coin. Each row shows step and position each time one of them changes, once both exist.
import random
random.seed(4)
position = 0
for step in range(1, 5):
if random.choice(["up", "down"]) == "up":
position = position + 1
else:
position = position - 1Sign 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: Shuffle with random.shuffle: no for loop and no manual swapping.
This code works: it shuffles the cards with a hand-written loop. Python's random.shuffle does exactly the same steps, so with the same seed it gives the same order. Rewrite it to call random.shuffle, with no loop. 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.
Write make_round(questions, size, seed), which seeds the generator, returns size different questions in random order with sample, and raises ValueError if size is larger than the number of questions. Check its properties and print:
3 True True same round: True too many: ValueError
The first line is the round size, whether every question is different, and whether every question came from the bank.
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.