Open lesson

Mission: check Voss's total

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

Visit every receipt, count distinct IDs, and calculate a total without treating copies as new events.

Voss points to four rows and claims “four departures.” Imani gives you authorized copies: R31 quantity 1, R31-copy quantity 1 with the same original ID, R32 quantity 2, and R33 quantity 3. Every row says “received,” not “released.” The story's meeting is near; take the time you need. Mara asks for a row-by-row report.

Your mission

  1. Give the human positions from enumerate(receipts, start=1) and the Python list indices.
  2. Describe how seen, the count, and total change at each row.
  3. Report distinct IDs and total received quantities, flagging the copy.
  4. Explain why this does not prove four departures and what to do if two R31 rows disagree on quantity.

How to check your work

  • You give positions 1–4 and indices 0–3 separately.
  • You do not add the R31 copy to count or total, but flag it.
  • You get 3 distinct IDs and 1 + 2 + 3 = 6 parts recorded as received.
  • You separate received from released and request review of conflicting copies.

Course example

receipts = [{'id': 'R21', 'quantity': 2},
            {'id': 'R21', 'quantity': 2},
            {'id': 'R22', 'quantity': 1}]
seen = set()
duplicates = []
count = 0
total = 0
for position, receipt in enumerate(receipts, start=1):
    if receipt['id'] not in seen:
        seen.add(receipt['id'])
        count = count + 1
        total = total + receipt['quantity']
    else:
        duplicates.append(receipt)
print(count)
print(total)
print(len(duplicates))

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 human positions from `enumerate(receipts, start=1)` and the Python list indices.
# Describe how `seen`, the count, and total change at each row.
# Report distinct IDs and total received quantities, flagging the copy.
# Explain why this does not prove four departures and what to do if two R31 rows disagree on quantity.

exemple.py

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

receipts = [{'id': 'R21', 'quantity': 2},
            {'id': 'R21', 'quantity': 2},
            {'id': 'R22', 'quantity': 1}]
seen = set()
duplicates = []
count = 0
total = 0
for position, receipt in enumerate(receipts, start=1):
    if receipt['id'] not in seen:
        seen.add(receipt['id'])
        count = count + 1
        total = total + receipt['quantity']
    else:
        duplicates.append(receipt)
print(count)
print(total)
print(len(duplicates))