Open lesson

Mission: hand Imani your first tool

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

Assemble a small program that validates counts, calculates repeats, displays clear refusals and proves its behavior on known cases.

The meeting room doors open in a few fictional minutes. Voss claims your ID on an authorization is enough to accuse you. Mara sets down three batches: P has 8 rows and 7 distinct IDs; Q has 2 rows and 3 IDs; R has 4 rows and 4 IDs. Two original files carry the same authorization number. Imani wants a demonstrable tool, a clear refusal for Q and access to originals.

Your mission

  1. Write the input, validation, calculation and output path for one batch.
  2. Calculate expected output for P, Q and R without hiding Q.
  3. Suggest a normal test, a boundary test and a refusal test.
  4. Explain exactly what the repeated number suggests and what is missing before accusing anyone.

How to check your work

  • Validation comes before subtraction and each output names its batch.
  • P gives 1; Q says REFUSED; R gives 0.
  • Tests check a known difference, a zero boundary and ValueError for an impossible input.
  • The copy suggests a duplicated trace; actor, time and source remain for investigators to establish.

Course example

def repeats(rows, distinct):
    if rows < 0 or distinct < 0 or distinct > rows:
        raise ValueError('impossible count')
    return rows - distinct

def report_line(name, rows, distinct):
    try:
        number = repeats(rows, distinct)
    except ValueError as error:
        return f'{name}: REFUSED ({error})'
    return f'{name}: {number} repeat(s)'

assert repeats(5, 4) == 1
assert repeats(0, 0) == 0

batches = [
    {'name': 'A', 'rows': 5, 'distinct': 4},
    {'name': 'B', 'rows': 3, 'distinct': 4},
    {'name': 'C', 'rows': 2, 'distinct': 2},
]
for batch in batches:
    print(report_line(batch['name'], batch['rows'], batch['distinct']))

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.

# Write the input, validation, calculation and output path for one batch.
# Calculate expected output for P, Q and R without hiding Q.
# Suggest a normal test, a boundary test and a refusal test.
# Explain exactly what the repeated number suggests and what is missing before accusing anyone.

exemple.py

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

def repeats(rows, distinct):
    if rows < 0 or distinct < 0 or distinct > rows:
        raise ValueError('impossible count')
    return rows - distinct

def report_line(name, rows, distinct):
    try:
        number = repeats(rows, distinct)
    except ValueError as error:
        return f'{name}: REFUSED ({error})'
    return f'{name}: {number} repeat(s)'

assert repeats(5, 4) == 1
assert repeats(0, 0) == 0

batches = [
    {'name': 'A', 'rows': 5, 'distinct': 4},
    {'name': 'B', 'rows': 3, 'distinct': 4},
    {'name': 'C', 'rows': 2, 'distinct': 2},
]
for batch in batches:
    print(report_line(batch['name'], batch['rows'], batch['distinct']))