Python only what you need
Build the first working score labeler
Page 3 implements the shortest complete path for the threshold score labeler (`scores.py`) with inspectable intermediate values.
1Learn the idea
Read
Implement the minimal working path
Build only what the claim requires: three float scores and one threshold produce deterministic yes/no labels plus a positive count without repeating the rule. Prefer boring, deterministic code over frameworks you cannot yet explain. Run the path twice; identical output on this fixture is a feature, not a lack of creativity.
Read
Run the working path
def label_scores(scores, threshold):
labels = ["yes" if score >= threshold else "no" for score in scores]
return labels, labels.count("yes")
scores = [0.2, 0.9, 0.4]
labels, positive_count = label_scores(scores, 0.5)
for score, result in zip(scores, labels):
print(f"{score:.1f} -> {result}")
print("positive:", positive_count)
Expected output:
0.2 -> no
0.9 -> yes
0.4 -> no
positive: 1
The comparison appears once. Returning both values makes the result testable without scraping printed text.
Read
Trace one input end to end
Narrate the journey from raw input to result for a single example from scores=(0.2,0.9,0.4), threshold=0.5. If you cannot name an intermediate, the implementation is still too opaque for this lab. Only after this path is solid should you generalize data sources or UI.
Read
Lab notebook: intermediates worth printing
While implementing the score labeler, print or log at least three intermediates that map to the claim (three float scores and one threshold produce deterministic yes/no labels plus a positive count without repeating the rule). Good intermediates are values a teammate could recompute with a calculator or diff. Bad intermediates are framework traces you cannot explain.
Re-run with scores=[0.2,0.9,0.4], threshold=0.5 twice. If the second run differs, either the path is nondeterministic (document the seed) or you have hidden global state—both are lab bugs until named.
Read
Worked judgment
Stop adding features once the path supports accept or reject a model score using one shared cutoff. Extra UI, extra tools, or extra models belong in later chapters. The mastery bar for this page is simply: a deterministic end-to-end path with intermediates.
Read
Guided practice
Predict the output for [0.49, 0.50, 0.51] before running it. Then change only the threshold to 0.51 and explain which labels change and why.
Read
Independent transfer
Write flag_temperatures(readings, limit) that returns labels and a count. Equality must count as an alert. Use [29.9, 30.0, 30.1] with limit 30.0; expected labels are ["ok", "alert", "alert"].
Go deeper
Before you start
Why this matters
Without running code, predict the final output for fixture scores=(0.2,0.9,0.4), threshold=0.5. Name one intermediate value that would prove the prediction. Then answer: what could look successful while actually being wrong at this stage for the score labeler?
In the wild
See how this idea shows up as a product and a company — then come back to the lesson. Skills transfer across vendors.
Related lessons
Check your understanding
Page assessment
Answer from memory. Completion is saved from this evidence, not from opening the next page.
All responses are required.