Read numbers and lists
Optional arithmetic and percentage refresher — return to this activity
A café order has two quantities: item count and price per item. Python stores a number such as 3 separately from text such as "3". A list keeps several values in order; an index names a position, starting at zero.
Python workshop: public teaching inputs
All people, records and numbers in this pack are authored teaching examples. They are not records or performance claims about real organizations.
- PY1 · Price rows are [[2, 3], [4, 2]]: each row contains quantity then credits per item. Expected line totals are 6 and 8 credits. Lists use zero-based indexing: the first item has index 0.
- PY2 · A function accepts input and returns a result. The supplied workshop demonstrates line_total(quantity, price). A branch selects an action; a loop repeats it. Negative quantity is rejected, not silently changed.
- PY3 · A test compares observed behavior with an independently calculated expectation. A passing example alone is not proof for every input. Empty, zero and malformed inputs need stated behavior.
- PY4 · Run the downloadable Python workshop locally. The page retains notes, not executed Python. Imported or pasted code is inert text. The separate reproducibility module supplies a second, scientific comparison starter.
Follow one order through the calculation
orders[0][0]orders[0][1]2 * 3The first index selects a row; the second selects a column. A second row [4, 2] contributes 8 credits: the running subtotal goes 0 → 6 → 14. Add a two-credit delivery fee once, after both rows, to get 16.
The values and their units travel together. A square table can keep the same shape even when its columns have the wrong meaning.
Read the code with the example
An equals sign assigns a value to a name. Square brackets construct a list or select a position. The star multiplies; print displays the result. Text after # is a comment for readers, not an executed calculation.
order = [2, 3]
quantity = order[0]
price = order[1]
print(quantity * price) # 6Fixed worked example, not an in-browser interpreter. Predict a changed input before running your own saved file.
Worked example
For order = [2, 3], order[0] is quantity 2 and order[1] is price 3. Multiplication gives 2 × 3 = 6 credits. The expression “3” + “2” joins text into “32”; it does not add prices. print(…) displays a value so you can inspect it.
Check the boundary
A position is not a unit or a type. Keep quantity and credits-per-item labels beside the list; changing names or positions without changing the calculation can produce a plausible wrong number.