Read rows, columns and units
Optional arithmetic and percentage refresher — return to this activity
A table is a list of rows with a declared meaning for each column. Shape describes rows and columns. A two-by-two table has two rows, each with two values; equal dimensions alone do not prove the columns mean the same thing.
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.
A row [4] has no column 1. Reject it before multiplying; silently dropping it changes the order.
Read the code with the example
len returns the number of items. != means not equal. Validate a row before indexing it. This illustration assumes numeric inputs; the downloadable validator also rejects text, booleans, negative values and non-finite numbers. A rectangle of values still needs column names and units.
rows = [[2, 3], [4, 2]]
for row in rows:
if len(row) != 2:
raise ValueError("quantity and price required")
print(row[0] * row[1]) # 6, then 8Fixed worked example, not an in-browser interpreter. Predict a changed input before running your own saved file.
Worked example
[[2, 3], [4, 2]] has shape 2 × 2 and total 2 × 3 + 4 × 2 = 14. A row [4] has no price, so the supplied validator rejects it. Swapping columns preserves shape but changes interpretation; labels must travel with values.
Check the boundary
A rectangular table may still mix units, swap meanings or contain invalid values. Do not silently discard rejected rows: that changes the population represented by the reported total.