Open lesson

Mission: the zero absent from the file

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

Read a small CSV and JSON file, recognize headers and types, spot an unreadable value and keep the received file as a source.

In the story, Voss shows a slide where E9 has attempt = 0, claiming your ID launched another attempt. Mara hands you the received copy: its CSV says E7 / NOCTIS-01 / 2, E8 / TEST-02 / 1 and E9 / NOCTIS-01 / unknown. The attached JSON says {"event_id":"E7","attempt":2}. Imani demands a literal reading before contacting the vendor.

Your mission

  1. Name the header and three CSV records.
  2. Explain the type of E7’s attempt in CSV and in JSON.
  3. Say what happens when unknown is converted with int() and what the report should say.
  4. Explain whether Voss’s 0 appears in these files and which sources to preserve.

How to check your work

  • The header is event_id,vehicle,attempt; rows E7, E8 and E9 are recognized.
  • CSV reads '2' as text; JSON reads 2 as an integer.
  • int('unknown') raises ValueError; E9 stays a raw unreadable value.
  • No 0 for E9 appears in the supplied files; preserve raw CSV/JSON, source and receipt date.

Course example

import csv
import json
from io import StringIO

csv_text = 'event_id,vehicle,attempt\nE7,NOCTIS-01,2\nE9,NOCTIS-01,unknown\n'
json_text = '{"event_id":"E7","attempt":2}'

with StringIO(csv_text) as file:
    rows = list(csv.DictReader(file))
with StringIO(json_text) as file:
    record = json.load(file)

print(rows[0]['attempt'], type(rows[0]['attempt']).__name__)
print(record['attempt'], type(record['attempt']).__name__)
try:
    int(rows[1]['attempt'])
except ValueError:
    print('E9: unreadable attempt')

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.

# Name the header and three CSV records.
# Explain the type of E7’s `attempt` in CSV and in JSON.
# Say what happens when `unknown` is converted with `int()` and what the report should say.
# Explain whether Voss’s 0 appears in these files and which sources to preserve.

exemple.py

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

import csv
import json
from io import StringIO

csv_text = 'event_id,vehicle,attempt\nE7,NOCTIS-01,2\nE9,NOCTIS-01,unknown\n'
json_text = '{"event_id":"E7","attempt":2}'

with StringIO(csv_text) as file:
    rows = list(csv.DictReader(file))
with StringIO(json_text) as file:
    record = json.load(file)

print(rows[0]['attempt'], type(rows[0]['attempt']).__name__)
print(record['attempt'], type(record['attempt']).__name__)
try:
    int(rows[1]['attempt'])
except ValueError:
    print('E9: unreadable attempt')