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.
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.
Use re.findall to collect every hashtag in post: a # followed by one or more word characters. Store the list in tags 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 ___ with a pattern so that only codes of exactly three capital letters followed by two digits are valid, and the program prints ABC12 True, AB123 False, XYZ99 True and XYZ999 False.
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.
A PIN must be exactly four digits, so the program should print 1234 True, 12345 False and a1234 False. It accepts the bad PINs. 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.
Each row shows key and total each time one of them changes, once both exist.
import re
total = 0
for key, value in re.findall(r"(\w)=(\d+)", "a=4 b=10 c=1"):
total = total + int(value)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 masked with re.sub on the text before the last four characters: no for loop.
This code works, but it hides digits with a loop. Rewrite it so masked is built with one re.sub call and no for 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 extract(text), which returns a dictionary with emails (every match of word characters or dots, an @, then word characters with at least one dot-separated part) and phones (numbers written as three digits, a dash and four digits), each list sorted. Print each list on its own line. The output should be:
['ana.lee@shop.com', 'sales@shop.co.uk'] ['555-0101', '555-0199']
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.