Open lesson

Mission: the page Voss forgot

Command palette

This mission workspace keeps code and notes in this browser tab. Export them before closing it. Running code is practice, not an automatic grade for the mission.

Brief

Collect every page announced by a service, handle a temporary failure without skipping a page and clearly report an incomplete collection.

In the story, Voss displays E7 then E9 and claims no night transfer exists. Imani hands you fictional replies: page 1 has E7 and points to 2; page 2 first returns 503, then has TRANSFER-7 and points to 3; page 3 has E9 and no next page. Mara gives you a few fictional minutes to rebuild the delivery without a real network.

Your mission

  1. Give the exact sequence of requested pages and total request count.
  2. Give the final event list when page 2’s retry succeeds.
  3. Explain what must be reported if page 2 fails on the second try as well.
  4. Say why E7 and E9 alone do not prove absence of a transfer, and which response details to keep.

How to check your work

  • Requests are 1, 2, 2, 3: four total.
  • The full list is E7, TRANSFER-7, E9.
  • After two failures, status is INCOMPLETE; page 3 is not treated as though nothing happened.
  • Announced page 2 must be checked; preserve codes, pages, attempts and raw data.

Course example

PAGES = {
    1: {'events': ['E7'], 'next': 2},
    2: {'events': ['TRANSFER-7'], 'next': 3},
    3: {'events': ['E9'], 'next': None},
}
visits = {}

def fake_get(page, timeout_seconds):
    visits[page] = visits.get(page, 0) + 1
    if page == 2 and visits[page] == 1:
        return {'status': 503}
    return {'status': 200, **PAGES[page]}

def get_with_retries(page):
    for attempt in (1, 2):
        response = fake_get(page, timeout_seconds=5)
        if response['status'] == 200:
            return response
        if response['status'] != 503:
            raise ValueError('unexpected status')
    raise RuntimeError('page incomplete')

page = 1
seen = set()
events = []
while page is not None:
    if page in seen:
        raise ValueError('repeated page')
    seen.add(page)
    response = get_with_retries(page)
    events.extend(response['events'])
    page = response['next']
print(events)

Code

Use Tab to leave the editor. Ctrl+Enter runs the source. The lines beginning with # are task reminders. Python ignores them. Write your code beneath them.

Python console

Loading laboratory…

Explore Python or SQL here; this is not an operating-system shell.

This is a disposable browser experiment. The code run here is not recorded as a completed mission.

Each command starts a fresh disposable worker: it runs a captured copy of your current source, then your command with the lesson fixtures. Changes are discarded afterward. Commands never save source or award XP. Ctrl+Enter executes the command.

Virtual workspace files

Source and declarative assets are readable here without JavaScript. Python input files are created at runtime; SQL setup initializes the disposable database.

source.py

Current editor source. Inspection shows your current edits.

# Give the exact sequence of requested pages and total request count.
# Give the final event list when page 2’s retry succeeds.
# Explain what must be reported if page 2 fails on the second try as well.
# Say why E7 and E9 alone do not prove absence of a transfer, and which response details to keep.

exemple.py

Declarative lesson asset; this is not a file created in the Python filesystem.

PAGES = {
    1: {'events': ['E7'], 'next': 2},
    2: {'events': ['TRANSFER-7'], 'next': 3},
    3: {'events': ['E9'], 'next': None},
}
visits = {}

def fake_get(page, timeout_seconds):
    visits[page] = visits.get(page, 0) + 1
    if page == 2 and visits[page] == 1:
        return {'status': 503}
    return {'status': 200, **PAGES[page]}

def get_with_retries(page):
    for attempt in (1, 2):
        response = fake_get(page, timeout_seconds=5)
        if response['status'] == 200:
            return response
        if response['status'] != 503:
            raise ValueError('unexpected status')
    raise RuntimeError('page incomplete')

page = 1
seen = set()
events = []
while page is not None:
    if page in seen:
        raise ValueError('repeated page')
    seen.add(page)
    response = get_with_retries(page)
    events.extend(response['events'])
    page = response['next']
print(events)