The idea
You do not need to invent every tool in Tony’s workshop before using it. Likewise, Python’s standard library provides tools for numbers, text and structured data. Learn what goes in, what comes out and what assumptions a tool makes. The period in math.sqrt means “look up sqrt inside math”; it is not a decimal point in this context.
A tiny experiment
PYTHON 3PREDICT BEFORE YOU RUN
import math
import json
print(math.sqrt(81))
record = {"clues": 3, "checked": True}
print(json.dumps(record))Reveal the expected output
9.0
{"clues": 3, "checked": true}Read it one step at a time
- import math makes the math module available. sqrt returns a square root.
- json.dumps converts the record into JSON text, a format other programs can read.
- JSON spells true in lower case. Python spells its Boolean True with a capital T. They are different syntaxes.
Make one change
Change 81 to 100 and clues to 4. Predict both output lines.
Check your thinking
The first is 10.0. The JSON record contains "clues": 4.
Keep following the trail
- Activity 03: Read Tony's message
- Activity 07: Read the radio-station note
- Activity 10: Repair the Genesis copy
- Activity 12: Save code as a contribution
Sources & further reading
Companion notes for Coding Adventure by James Colby. Historical claims link to their sources; the examples are written for this learning trail.