DynamicVibePython learning
How to study · reference & help

One lesson at a time

Read the idea, then follow the named exercise steps. On a phone, use Idea, Code and Output to switch views. Review days begin with recall before the rebuild. A self-review mark is not a scored answer.

Run, inspect, repair

Run loads Python in your browser on the first use, so you need an internet connection. Read Output and the check result. Stop interrupts a run; it keeps your code. Reset restores the selected starter, replacing that exercise’s draft. Use an authored hint before asking for help.

Keep your work

Code drafts, progress and Notes save on this device when browser storage is available. They do not sync through your login. Use Backup & records above to download saved learning records, preview an import or undo the latest import. Copy unsaved text first; clearing browser data can remove local work. A save warning means you should copy your work before leaving.

Practice files and reports

Each browser Run starts in a fresh temporary workspace. A sample file exists only when that run’s code creates it; these are not your computer’s files. On report tasks, use Preview to inspect the actual text and Download to request a copy before another Run, Reset, exercise change or leaving. Reports do not save through tutor login. Read files and write reports.

Get tutoring when you need it

Lessons and checkpoints do not need tutor login. Unlock the tutor through Training’s shared tutor access, then use its return link to come back here. Your question is only sent when you press Send. Do not paste passwords or private production data.

Python words in plain language

Assignment and type
frames = 96 binds a name to an integer. "96" is text, not the same numeric value. Values and names.
List and index
A list keeps items in order. Positions start at zero; the final nonnegative index is length minus one. List lookups.
Loop and indentation
A for loop processes each item. Indentation groups its repeated statements; a statement outside the block runs separately. Loops.
Parameter, argument and Return
A parameter names an input in a definition; an argument supplies its value in a call. Return gives a result to the caller; print displays it. A function that only prints returns None. Functions.
Dictionary and schema
A dictionary labels values with keys. A schema states the required fields and types; a missing fact is not automatically zero. Dictionaries · Validation.
File, CSV and JSONL
A file stores bytes/text. CSV needs a quoting-aware parser; JSONL contains one JSON value per line. Browser practice files are temporary, not computer files. CSV · JSONL.
Denominator and evidence
A rate divides a count by its declared eligible total. Keep exclusions visible. A quiz score, practical check and self-review are different evidence. Quality rates.

Read the error, then make one repair

SyntaxError / IndentationError
Python could not parse the code. Inspect the named line and the preceding line for a missing colon, unmatched quote/bracket or inconsistent indentation. Review blocks.
NameError
A name has no value here. Compare case and spelling, and check that assignment happens before use. Do not replace an unknown parameter with a fixed sample.
TypeError / ValueError
A wrong kind of value or an unacceptable value can fail an operation. Inspect the supplied input and declared policy; do not broadly suppress the error. Narrow error handling.
IndexError / KeyError
The requested position or key is missing. Inspect the collection and interface instead of guessing a fallback. Indices · Keys.
Run stays loading / runtime or checker unavailable
This is not proof that your answer is wrong. Stop if available, copy your draft, check your connection and retry. If it repeats, keep the visible error and use the readable lesson/hints. Never reset or clear browser storage as the first repair.
Expected sample prints, but a check fails
Read the named contract and test changed/empty inputs. The helper may return None, use a fixed value or stop too early even when the sample looks right. A failed check is not a request to copy the expected output.

Press Escape while working inside this panel to close it and return focus to its summary. Without JavaScript, use the summary again. For local Studio commands, use terminal troubleshooting.

← Route Week 5 · Day 25 · Checkpoint

Dataset validation review

Loading today's steps…
Lesson idea Tap to fold
Recall

Name three reasons to reject a human-data record.

Show the answer

For example: missing id, unknown label, invalid score, malformed JSON, or duplicate id.

Today

Audit a batch without silently losing rows

The original trace converts string/integer scores for a controlled dictionary; the rebuild checks raw nonempty IDs and string labels; the repair handles missing integer scores. Their assumptions differ. They are demonstrations, not one production schema. The independent task combines the ideas under a new, explicit policy.

enumerate(lines, start=1) supplies each line’s number and value. continue moves to the next line. A set stores IDs already accepted; membership checks detect repeats, and add records a newly accepted ID. Create the set inside the function so a second call starts fresh.

For decoded data, check types before operations. Booleans are subclasses of int in Python, so an integer-only score policy must explicitly exclude bool. Catch the expected JSONDecodeError at decoding, then report each first validation failure instead of hiding all errors. The 59-minute practice sequence may be split before the independent task; the quiz is separate.

# Audit a batch without silently losing rows.
import json

text = '{bad}\n{"item_id":"Museum"}\n '
for number, line in enumerate(text.splitlines(), start=1):
    if not line.strip():
        print(number, "ignored blank")
        continue
    try:
        row = json.loads(line)
    except json.JSONDecodeError:
        print(number, "json error")
        continue
    print(number, row.get("item_id"))

1 json error, 2 Museum, then 3 ignored blank. This trace teaches decoding and line numbers; it does not implement the full independent schema.

Use the independent brief for every acceptance and rejection rule. Return an auditable result and check a second batch; the quiz score stays separate.

Predict, explain, then test

These three brief checks are self-reviewed, not a scored quiz. Answer before opening the comparison. Coding checks follow the stated task assumptions on unfamiliar inputs.

Separate types

Why reject the JSON boolean true as an integer score?

Compare your answer · self-reviewed

It decodes to True, which is an int subclass in Python. The explicit schema excludes booleans.

Trace duplicates

Does an invalid row with ID Museum reserve that ID?

Compare your answer · self-reviewed

No. Only a fully valid accepted row reserves an ID; the first later valid row may still pass.

Keep evidence

Why return line numbers and first rejection reasons rather than quietly drop bad rows?

Compare your answer · self-reviewed

They make exclusions inspectable and reproducible. A record count alone cannot explain missing data.

Independent transfer: audit a JSONL batch

Write audit_jsonl(text) in your own implementation. This new policy is stricter than the original demonstration helpers:

  1. Accept a string argument; raise TypeError for a different caller type.
  2. Visit text.splitlines() in order, using one-based line numbers. Count whitespace-only lines as ignored. A trailing line ending creates no extra line.
  3. Decode each nonblank line with json.loads. Catch JSONDecodeError for malformed text and report reason json. A decoded non-dictionary reports record.
  4. Require item_id to be a string whose stripped value is nonempty. Store that stripped ID; otherwise report item_id.
  5. Allow only the exact string labels chosen and rejected; otherwise report label.
  6. Require score to be an integer from 1 through 5, excluding booleans. Do not convert numeric strings or decimals; otherwise report score.
  7. Keep the first valid occurrence of a trimmed ID. A later valid occurrence reports duplicate. Invalid rows do not reserve IDs.
  8. Apply those rejection reasons in the order above; report only the first reason for a line. Return {records: [...], errors: [{line: n, reason: ...}], ignored: n}, using Python string keys. Accepted records contain only item_id, label and score; extra input fields are ignored. Preserve order, reset state on each call and return data rather than only printing.

Decoding uses Python json.loads: repeated property names use its last value. Duplicate item IDs follow the separate first-valid-record rule above. JSON syntax and this course schema are different checks.

Select the task in the exercise controls. Its unfinished starter should fail until you implement the rules. The checkpoint’s practical link selects the task and opens this brief without running Python or awarding evidence. Review JSONL decoding or narrow error handling.

Read the unfinished starter without running Python
# Decode rows, then enforce the independent schema.
import json

# Implement the stated policy; this is unfinished.
def audit_jsonl(text):
    return {"records": [], "errors": [], "ignored": 0}

# Inspect counts, not a copied report string.
sample = (
    '{"item_id":" a1 ","label":"chosen","score":5}\n'
    '{broken\n'
    '{"item_id":"a1","label":"rejected","score":3}\n'
    ' \n'
)
result = audit_jsonl(sample)
print("Accepted:", len(result["records"]))
print("Rejected:", len(result["errors"]))
print("Ignored:", result["ignored"])

The sample prints Accepted: 1, Rejected: 2, Ignored: 1 on separate lines. Explain why the second a1 is rejected and why an invalid earlier row would not reserve an ID. The checks inspect returned data for new batches and repeated calls. Quiz results and practical evidence remain separate.

Now

Choose an exercise to load its prompt.

day-25.py standard Python · runs in this browser
Output

Loading exercises…


    
    

Section 5 checkpoint

Answer five questions, review explanations and use the linked refreshers. Your score does not award the independent JSONL audit; tutor login is not required.

AI Tutor

The tutor mounts here when JavaScript is available. The lesson above stays readable without it.