Open lesson

Mission: one rule for three packets

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

Write a simple function, give it different values, and reuse its result without confusing calculation with proof.

Imani will receive three packets of authorized copies before a fictional deadline. A has 5 rows for 4 distinct IDs; B has 3 rows for 3 IDs; C has 7 rows for 5 IDs. Voss calls every extra row evidence against you. Mara asks for a repeatable calculation and a sentence explaining what it cannot prove.

Your mission

  1. Write repetitions(rows, distinct) with a local variable and return.
  2. Call it for A, B, and C and give three results.
  3. Explain how return differs from print().
  4. If the function is in inventory.py, write the import and a careful conclusion for Imani.

How to check your work

  • Your function calculates rows - distinct and returns it.
  • You get 1 for A, 0 for B, and 2 for C.
  • You know return gives a value to the caller; print only displays.
  • You write from inventory import repetitions and do not turn extra rows into a verdict.

Course example

def repetitions(rows, distinct):
    extra = rows - distinct
    return extra

first_batch = repetitions(4, 3)
second_batch = repetitions(6, 4)
print(first_batch)
print(second_batch)

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 `repetitions(rows, distinct)` with a local variable and `return`.
# Call it for A, B, and C and give three results.
# Explain how `return` differs from `print()`.
# If the function is in `inventory.py`, write the import and a careful conclusion for Imani.

exemple.py

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

def repetitions(rows, distinct):
    extra = rows - distinct
    return extra

first_batch = repetitions(4, 3)
second_batch = repetitions(6, 4)
print(first_batch)
print(second_batch)