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. The datetime module knows that 2024 is a leap year.
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.
Write days_until(today, event), which returns the number of days from today to event (both dates). Print the days from 1 December 2024 to 25 December 2024, and from 1 December 2024 to 1 January 2025.
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 format so the program prints Friday 15 March 2024.
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 reads a booking time and should print 2024-07-04 18:30:00. The format does not match the text. Fix the format string.
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 week and day each time one of them changes, once both exist. Python shows a date's repr as datetime.date(2024, 1, 29).
from datetime import date, timedelta
day = date(2024, 1, 22)
for week in range(1, 4):
day = day + timedelta(weeks=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: Read the date with date.fromisoformat and print it with isoformat(): no split( and no hand-built f-string.
This code works, but it builds and splits date strings by hand. Rewrite it to use date.fromisoformat and isoformat(), with no split( and no f-string building the date. 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 subscription is (name, start, days) with the start as text like 12/02/2024. Write renewal(start_text, days), which parses the start with strptime and returns the renewal date. Print each name with its renewal as Mon 13 May style text, in renewal order, then the names whose renewal falls on a weekend. The output should be:
Ben: Thu 14 Mar Ana: Sat 13 Apr Cy: Sun 12 May Weekend: ['Ana', 'Cy']
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.