Quarry School

Programming in Python / Quantities and text

Quantities and text

Subject: Computing

All 5 lessons, in order.

The unit at a glance

  1. Choose an arithmetic operator

    A volunteer is measuring ribbon for four display frames.

  2. Group a calculation

    Four supply kits sit on a table.

  3. Keep a remainder

    You have a stack of 38 postcards and display sleeves that hold six cards each.

  4. Index and slice a label

    A shelf label reads RACK27.

  5. Format a line of output

    A volunteer writes shelf lengths on small bin cards.

Rules (5)
  • Choose an arithmetic operator

    Use + to add an amount, - to take an amount away, * to find the total of equal groups and / to share an amount equally. In 4 * 6, the operands are 4 and 6, the numbers that * works on.

    Start with whole numbers such as 4 and 20. To subtract, put the starting amount first and the amount you remove second. To divide, put the amount to share first and the number of shares second. The number to the right of / is the divisor. In this example, it counts the frames, so it must be at least one.

    Python calls numbers such as 2.5 and 5.0 floats. In these examples, / gives a float even when the share is a whole number of meters.

  • Group a calculation

    When parentheses group an addition, do the addition inside them before multiplying by the number outside. In a calculation with addition and multiplication and no grouping parentheses, Python does the multiplication first.

  • Keep a remainder

    The total is how many items you start with. It can be any whole number from zero up. The group size is how many items fit in one full group. It can be any whole number from one up. Here, whole numbers are the counts 0, 1, 2 and so on.

    Put the total on the left and the group size on the right. With // between them, Python gives the number of full groups. With % between them, it gives the remainder. The remainder is smaller than the group size. When it is zero, the full groups use all the items.

  • Index and slice a label

    With label as the name of the string, label[1] picks the character at index 1. In label[2:5], 2 is the start and 5 is the stop. That takes positions 2, 3, and 4. When the start is smaller than the stop and both numbers are in the range from zero through the total number of characters, subtract the start from the stop to get the slice’s character count.

  • Format a line of output

    Put f right before the opening quote. Inside the quotes, put the names whose values you want to use inside braces. Type the literal pieces where they should appear. Write :.2f after the number’s name inside its braces. For the lengths on these cards, .2f writes out two places after the decimal point, adding a zero or rounding the displayed number as needed.

    In these examples, print(...) displays the finished text and then adds a newline, which ends the line.

Recipes (5)
  • Choose an arithmetic operator
    1. Say what is happening. Are you adding a piece, taking one away, finding the total of equal groups or sharing equally?
    2. Choose the operator for that action. Put it between the two numbers in the order described above.
    3. To show the result, type print and put the calculation inside the parentheses ( and ). Type the source lines below in a file in your editor. Save it as ribbon.py and run it with Python 3.13. You can also follow along on paper with the printed trace, which shows the results in order.
  • Group a calculation
    1. Write 6 + 3 to count the pieces for one kit.
    2. Put parentheses around that addition to get (6 + 3).
    3. Put * 4 after the group to count four kits.
  • Keep a remainder
    1. Write down the total and the group size.
    2. Use // between those numbers to find the number of full groups.
    3. Use % between the same numbers to find the remainder.
    4. Multiply the group count by the group size and add the remainder. Check that you get the total and that the remainder is smaller than one full group.
    5. When you type the program, cards = 38 gives the name cards the value 38. The line cards_per_sleeve = 6 gives the group size its own name, with underscores between the words.
  • Index and slice a label
    1. Number the boxes from left to right, starting at 0.
    2. Give the text the name label on the first line. The equals sign = tells Python to use the name on the left for the text on the right.
    3. After label, put the position in square brackets for one character. For a slice, put the start and stop in the brackets with a colon between them.
    4. To display the result, put your selection inside the parentheses of print(). The text print() displays is the output. For these labels, print() displays the text without the surrounding quotes.
    5. In a text editor, type the three nonblank lines under Code in the worked example. Keep the blank line and start each line at the left edge. Run the file with Python 3.13. If you use the Python shell, where you can run one line at a time, type each nonblank source line after the >>> shown on screen and press Enter.
  • Format a line of output
    1. Give each value a name. Put the shelf name in quotes and write the length as a number. On each line, = gives the name on the left the value on the right.
    2. Inside print(...), start the template with f". Write {name} where the shelf name goes. Type a colon and one space after it.
    3. Add {length:.2f}, then one space and m. Type the closing quote and the closing parenthesis ).
    4. Predict the printed line. Read the name, the colon and space, the number with two digits after the decimal point, then the space and unit.
Traps (5)
  • Choose an arithmetic operator

    If you reach for the letter x when you mean “times,” type the asterisk *. That is Python’s multiplication sign.

    Both numbers in 20 / 4 are whole numbers. The length per frame is exactly 5 m, and Python displays that result as 5.0. The .0 is part of how Python writes this float.

  • Group a calculation

    Reading 6 + 3 * 4 strictly from left to right would give 36. Python does 3 * 4 first, which counts 12 rings, then adds six clips once, for 18 pieces. To count six clips in every kit, group the two counts as (6 + 3) * 4.

  • Keep a remainder

    If you catch yourself reading % as “percent,” read 38 % 6 aloud as “How many cards are left?” Its answer counts two loose cards. If you swap the two results, you get two full sleeves and six loose cards. Six loose cards would fill one more sleeve, so the swap fails the remainder check.

  • Index and slice a label

    If you start numbering at 1, you’ll pick R for index 1. Label that first box 0 and the next box 1 to find A. If you include box 5 in the slice, you’ll get CK27. Place your pencil on the line before box 5 and leave the 7 on the far side.

  • Format a line of output

    If you see braces in the printed line, check for the f before the opening quote. In this example, leaving it out makes Python print the text inside the quotes as written, braces and all. With the prefix in place, the format instruction controls the number’s appearance on the card. length still holds 3.5 after the program prints 3.50.

Lesson 1 of 5

Choose an arithmetic operator

Subject: ComputingOpen this lesson
Leans on 1Comes back in 0

1 In plain words

A volunteer is measuring ribbon for four display frames. Each roll holds 6 meters. Here, m stands for meters. The volunteer lays out four rolls, adds a spare piece, cuts off some ribbon and shares what is left equally. Each frame needs the same length.

Read 4 * 6 as “four times six.” The * is an operator, a symbol that tells Python what calculation to do. Remember to name the action first. Look up its symbol in The rule below.

2 Picture it

Four rolls4 × 6 → 24 mAdd the spare+ 5 m → 29 mCut a piece− 9 m → 20 mShare equally÷ 4 → 5 m

Four 6 m rolls give 24 m. The spare 5 m brings it to 29 m. Cutting 9 m leaves 20 m. Dividing that among four frames gives 5 m per frame.

Follow the ribbon from four rolls to four equal pieces.

3 Why

Four rolls of the same length give you four groups of 6 m. Multiplication finds their total in one calculation. Adding the spare makes the total longer. Taking away the cut piece is subtraction, and it tells you how much ribbon is left.

Dividing the ribbon into equal shares gives you the length for one frame. Put all four shares end to end to check that they add up to the length you divided.

4 The rule

Use + to add an amount, - to take an amount away, * to find the total of equal groups and / to share an amount equally.

In 4 * 6, the operands are 4 and 6, the numbers that * works on.

Start with whole numbers such as 4 and 20. To subtract, put the starting amount first and the amount you remove second. To divide, put the amount to share first and the number of shares second. The number to the right of / is the divisor. In this example, it counts the frames, so it must be at least one.

Python calls numbers such as 2.5 and 5.0 floats. In these examples, / gives a float even when the share is a whole number of meters.

5 How

  1. Say what is happening. Are you adding a piece, taking one away, finding the total of equal groups or sharing equally?
  2. Choose the operator for that action. Put it between the two numbers in the order described above.
  3. To show the result, type print and put the calculation inside the parentheses ( and ). Type the source lines below in a file in your editor. Save it as ribbon.py and run it with Python 3.13. You can also follow along on paper with the printed trace, which shows the results in order.

6 Worked example

Ribbon for four display frames

Python code
print(4 * 6)
print(24 + 5)
print(29 - 9)
print(20 / 4)

Standard input

Empty

Standard output

24
29
20
5.0

Save the code as ribbon.py and run the file in Python 3.13. The first three lines show whole meter counts. The last line shows the share as a float. Four shares of 5 m give the 20 m you divided.

Trace

Follow the ribbon lengths
ActionCalculationOutputExplanation
Count equal rolls4 * 624Four groups of 6 m make 24 m.
Add the spare24 + 529The extra piece adds 5 m.
Cut a piece29 - 920The cut removes 9 m.
Share equally20 / 45.0Four pieces of 5 m recover the 20 m you divided.

7 The trap

If you reach for the letter x when you mean “times,” type the asterisk *. That is Python’s multiplication sign.

Both numbers in 20 / 4 are whole numbers. The length per frame is exactly 5 m, and Python displays that result as 5.0. The .0 is part of how Python writes this float.

Quick checks

Quick check 1 of 2

You have 18 m of ribbon and cut off 7 m. Which calculation gives the length left, and what is the result?

Show the steps and the answer
Answer

Use 18 - 7. There are 11 m left.

Why: Cutting takes part of the ribbon away, so use -.

Source: Python Software Foundation, Python 3.13 Tutorial, 3.1.1. Numbers

Quick check 2 of 2

Share 15 m of ribbon equally across six signs. What calculation would you put inside print in a new editor file? What would the program display?

Show the steps and the answer
Answer

Type print(15 / 6). The program uses no keyboard input and prints 2.5 on one line.

Why: Use / to share the total equally. Six lengths of 2.5 m give 15 m, the full length you started with.

Source: Python Software Foundation, Python 3.13 Tutorial, 3.1.1. Numbers

Sources

  1. Python 3.13 Tutorial, 3.1.1. Numbers. Python Software Foundation. Python Software Foundation License Version 2. Read 26 Nov 2026.

Lesson 2 of 5

Group a calculation

Subject: ComputingOpen this lesson
Leans on 0Comes back in 0

1 In plain words

Four supply kits sit on a table. Each kit needs six clips and three rings. How many pieces do you need for all four kits?

When you calculate with numbers in Python, + means add and * means multiply. The curved marks ( and ) are called parentheses. Read (6 + 3) * 4 as “six clips plus three rings for one kit, four times.” Remember to put parentheses around the counts that go together.

2 Picture it

Kits36 total

Four kit trays each contain six filled marks for clips and three open marks for rings. That is nine marks per kit and 36 marks in all.

The parentheses group the contents of one kit.

3 Why

You need the same set of pieces for each kit. Add six clips and three rings to get nine pieces for one kit. Multiplying that nine by four counts one set of pieces for each of the four kits.

4 The rule

When parentheses group an addition, do the addition inside them before multiplying by the number outside.

In a calculation with addition and multiplication and no grouping parentheses, Python does the multiplication first.

5 How

  1. Write 6 + 3 to count the pieces for one kit.
  2. Put parentheses around that addition to get (6 + 3).
  3. Put * 4 after the group to count four kits.

6 Worked example

Count the pieces in four kits

Python code
print((6 + 3) * 4)
print(6 + 3 * 4)

Standard input

Empty

Standard output

36
18

Type both lines into an editor and run the file with Python 3.13. The first line counts all parts of all four kits. The second counts the clips once and the rings four times.

Trace

Compare how the two expressions group the supplies
ExpressionFirst valueOutputExplanation
(6 + 3) * 46 + 3 = 936Make a kit, then count four kits. Separately, 24 clips plus 12 rings also give 36.
6 + 3 * 43 * 4 = 1218Without the parentheses, multiply the rings first and count the clips once.

7 The trap

Reading 6 + 3 * 4 strictly from left to right would give 36. Python does 3 * 4 first, which counts 12 rings, then adds six clips once, for 18 pieces. To count six clips in every kit, group the two counts as (6 + 3) * 4.

Quick checks

Quick check 1 of 2

In 6 + 3 * 4, how many clips and how many rings does Python count?

Show the steps and the answer
Answer

6 clips and 12 rings, for 18 pieces.

Why: Python multiplies 3 * 4 first, then adds the six clips once.

Source: Python Software Foundation, An Informal Introduction to Python, 3.1.1. Numbers

Quick check 2 of 2

Three party bags each get seven cards and two stickers. Write a calculation with 3 first and parentheses around the two counts for one bag. How many pieces go in all three bags?

Show the steps and the answer
Answer

3 * (7 + 2) gives 27 pieces.

Why: Each bag gets nine pieces. Counting separately also gives 21 cards and 6 stickers, which add up to 27.

Source: Python Software Foundation, An Informal Introduction to Python, 3.1.1. Numbers

Sources

  1. An Informal Introduction to Python, 3.1.1. Numbers. Python Software Foundation. Python Software Foundation License Version 2. Read 26 Nov 2026.

Lesson 3 of 5

Keep a remainder

Subject: ComputingOpen this lesson
Leans on 0Comes back in 0

1 In plain words

You have a stack of 38 postcards and display sleeves that hold six cards each. Fill as many sleeves as you can. The number of full sleeves is your group count. The number of loose cards is your remainder.

In Python 3.13, read 38 // 6 as “How many full sleeves?” and 38 % 6 as “How many cards stay loose?” Remember // for full groups and % for leftovers. To look them up, find floor division and remainder in the Python tutorial’s Numbers section.

2 Picture it

SleevesLoose38 total

Six sleeves each contain six postcard marks. Two more marks sit outside the sleeves. The 36 packed cards and two loose cards account for all 38.

Count full sleeves and loose postcards separately.

3 Why

Six full sleeves use 36 cards. Adding the two loose cards gives the whole stack again. On paper, write 6 * 6 + 2 = 38. Read * as “times,” + as “plus” and = as “equals.”

Two is smaller than six. If six or more cards were loose, you could fill another sleeve.

4 The rule

The total is how many items you start with.

It can be any whole number from zero up. The group size is how many items fit in one full group. It can be any whole number from one up. Here, whole numbers are the counts 0, 1, 2 and so on.

Put the total on the left and the group size on the right. With // between them, Python gives the number of full groups. With % between them, it gives the remainder. The remainder is smaller than the group size. When it is zero, the full groups use all the items.

5 How

  1. Write down the total and the group size.
  2. Use // between those numbers to find the number of full groups.
  3. Use % between the same numbers to find the remainder.
  4. Multiply the group count by the group size and add the remainder. Check that you get the total and that the remainder is smaller than one full group.
  5. When you type the program, cards = 38 gives the name cards the value 38. The line cards_per_sleeve = 6 gives the group size its own name, with underscores between the words.

6 Worked example

Pack 38 postcards

Python code
cards = 38
cards_per_sleeve = 6

print(cards // cards_per_sleeve)
print(cards % cards_per_sleeve)

Standard input

Empty

Standard output

6
2

Save the code as postcards.py and run the file. Count full sleeves on the first output line and loose cards on the second. As a second check, subtract 6 repeatedly from 38 to reach 32, 26, 20, 14, 8 and 2.

Trace

Trace the postcard program
InstructionValue or outputExplanation
cards = 3838Give the name cards the postcard count.
cards_per_sleeve = 66Save the capacity of one sleeve.
cards // cards_per_sleeve6Six full sleeves use 36 cards. A seventh would require 42.
cards % cards_per_sleeve2Two cards remain. Six groups of six and two loose cards account for all 38 cards.

7 The trap

If you catch yourself reading % as “percent,” read 38 % 6 aloud as “How many cards are left?” Its answer counts two loose cards. If you swap the two results, you get two full sleeves and six loose cards. Six loose cards would fill one more sleeve, so the swap fails the remainder check.

Quick checks

Quick check 1 of 2

You have 26 gift tags. Each pocket holds 8. What do 26 // 8 and 26 % 8 give? Label each answer.

Show the steps and the answer
Answer

26 // 8 gives 3 full pockets. 26 % 8 gives 2 loose tags.

Why: Three pockets use 24 tags. The 2 left cannot fill a pocket of 8.

Source: Python Software Foundation, Python 3.13 Tutorial, Numbers

Quick check 2 of 2

A greenhouse has 319 plant tags. Each tray fits 29 tags. Predict the outputs of 319 // 29 and 319 % 29. What do they tell you?

Show the steps and the answer
Answer

319 // 29 gives 11 full trays and 319 % 29 gives 0 loose tags.

Why: Eleven trays of 29 use all 319 tags.

Source: Python Software Foundation, Python 3.13 Tutorial, Numbers

Sources

  1. Python 3.13 Tutorial, Numbers. Python Software Foundation. Python Software Foundation License Version 2. Read 26 Nov 2026.

Lesson 4 of 5

Index and slice a label

Subject: ComputingOpen this lesson
Leans on 0Comes back in 0

1 In plain words

A shelf label reads RACK27. To copy it onto a stock card, write from left to right and fit each letter or digit into its own box. Use the box numbers to read back one letter or digit, or several in a row.

Each letter or digit on the label is a character. Python calls a piece of text a string. Write "RACK27" with double quotes to tell Python 3.13 that it is text.

The marks [ and ] are square brackets. They go after the name for the text and hold the numbers that tell Python what to pick. The : mark is a colon. Between two numbers in the brackets, read it as “start at the first number and stop before the second.”

An index is a position number. Remember that Python starts at 0 on the left. Look up where to put the numbers and the colon in The rule.

2 Picture it

Index0R1A2C3K4257[2:5] → CK2

Six tiles read R, A, C, K, 2, 7. Their indexes are 0 through 5. The shaded slice covers C, K and 2. A stop line sits before the 7, at index 5.

Read the shelf tag from index 2 up to the stop at index 5.

3 Why

One number inside square brackets picks the character in that box as a string with one character. Two numbers separated by a colon pick a slice, a piece of the string. For the slices here, start at the box named by the first number. If the second number names a box, stop immediately before it. If it equals the character count, stop at the right edge of the last box. The slice is text, even if it contains only digits.

4 The rule

With label as the name of the string, label[1] picks the character at index 1.

In label[2:5], 2 is the start and 5 is the stop. That takes positions 2, 3, and 4. When the start is smaller than the stop and both numbers are in the range from zero through the total number of characters, subtract the start from the stop to get the slice’s character count.

5 How

  1. Number the boxes from left to right, starting at 0.
  2. Give the text the name label on the first line. The equals sign = tells Python to use the name on the left for the text on the right.
  3. After label, put the position in square brackets for one character. For a slice, put the start and stop in the brackets with a colon between them.
  4. To display the result, put your selection inside the parentheses of print(). The text print() displays is the output. For these labels, print() displays the text without the surrounding quotes.
  5. In a text editor, type the three nonblank lines under Code in the worked example. Keep the blank line and start each line at the left edge. Run the file with Python 3.13. If you use the Python shell, where you can run one line at a time, type each nonblank source line after the >>> shown on screen and press Enter.

6 Worked example

Read the shelf tag

Python code
label = "RACK27"

print(label[1])
print(label[2:5])

Standard input

Empty

Standard output

A
CK2

Type the program in an editor and keep the blank line. Run the file. To check the slice on paper, cover RA before the start and 7 after the stop. The uncovered characters read CK2.

Trace

Trace the two printed readings
InstructionOutputExplanation
label = "RACK27"—Give the whole tag the name label.
print(label[1])AIndex 1 is the second character when the first is at 0.
print(label[2:5])CK2Take positions 2, 3 and 4. Subtract 2 from 5 to check the three-character length.

7 The trap

If you start numbering at 1, you’ll pick R for index 1. Label that first box 0 and the next box 1 to find A. If you include box 5 in the slice, you’ll get CK27. Place your pencil on the line before box 5 and leave the 7 on the far side.

Quick checks

Quick check 1 of 2

With label holding "RACK27", what text does label[0:2] pick?

Show the steps and the answer
Answer

"RA"

Why: Read R at position 0 and A at position 1. Stop before box 2.

Source: Python Software Foundation, Python 3.13 Tutorial, 3.1.2. Text

Quick check 2 of 2

When label holds "MUG84", what do print(label[0]) and print(label[3:5]) display? Which positions does the slice use?

Show the steps and the answer
Answer

The first line is M. The second is 84. The slice uses positions 3 and 4.

Why: Give the label MUG84 five boxes. The first print line reads M from box 0. The second reads 8 and 4 from boxes 3 and 4, then stops at the right edge. A slice of a string gives a string.

Source: Python Software Foundation, Python 3.13 Tutorial, 3.1.2. Text

Sources

  1. Python 3.13 Tutorial, 3.1.2. Text. Python Software Foundation. Python Software Foundation License Version 2. Read 26 Nov 2026.

Lesson 5 of 5

Format a line of output

Subject: ComputingOpen this lesson
Leans on 0Comes back in 0

1 In plain words

A volunteer writes shelf lengths on small bin cards. Every card follows the same pattern. Write the shelf name, a colon and a space, the length with two digits after the decimal point, then a space and m. On these cards, m stands for meters. Read Oak: 3.50 m as “Oak, three point five zero meters.”

The text a program displays is one kind of output. To format output is to choose how it looks. In Python 3.13, put f or F immediately before the opening quote to start an f-string. That first letter is the prefix. This lesson uses f. Think of the f-string as a template, a pattern with places to fill in. Remember the prefix and the braces {}. For these lengths, look up .2f when you need two digits after the decimal point.

2 Picture it

f"{name}: {length:.2f} m"Oak: 3.50 mPrinted line

In the f-string, the name field connects to Oak, the text colon and space stays where it is, and the length field with .2f connects to 3.50. A space and m finish the printed line Oak: 3.50 m.

Follow the template fields to the printed shelf card.

3 Why

name and length are names for stored values. Python uses the text held by name to fill {name}. In {length:.2f}, Python takes the number held by length and uses .2f to write it. The colon inside those braces starts the format instruction. The colon after {name} is part of the card text, along with the space after it.

4 The rule

Put f right before the opening quote.

Inside the quotes, put the names whose values you want to use inside braces. Type the literal pieces where they should appear. Write :.2f after the number’s name inside its braces. For the lengths on these cards, .2f writes out two places after the decimal point, adding a zero or rounding the displayed number as needed.

In these examples, print(...) displays the finished text and then adds a newline, which ends the line.

5 How

  1. Give each value a name. Put the shelf name in quotes and write the length as a number. On each line, = gives the name on the left the value on the right.
  2. Inside print(...), start the template with f". Write {name} where the shelf name goes. Type a colon and one space after it.
  3. Add {length:.2f}, then one space and m. Type the closing quote and the closing parenthesis ).
  4. Predict the printed line. Read the name, the colon and space, the number with two digits after the decimal point, then the space and unit.

6 Worked example

Fill the Oak shelf card

Python code
name = "Oak"
length = 3.5

print(f"{name}: {length:.2f} m")

Standard input

Empty

Standard output

Oak: 3.50 m

Type the program into an editor and run the file. In the output, count two digits after the decimal point. Check the space after the colon and the space before m. The number assigned to length remains 3.5.

Trace

Follow the template onto the shelf card
Part of templateOutputExplanation
{name}OakUse the text stored in name.
Colon and space: Copy both literal characters.
{length:.2f}3.50Write the number with two decimal places.
Space and m mCopy these two literal characters. Then print ends the line.

7 The trap

If you see braces in the printed line, check for the f before the opening quote. In this example, leaving it out makes Python print the text inside the quotes as written, braces and all. With the prefix in place, the format instruction controls the number’s appearance on the card. length still holds 3.5 after the program prints 3.50.

Quick checks

Quick check 1 of 2

Keep the Oak values. In the editor, replace the last line with print("{name}: {length:.2f} m"). What line appears in the shell when you run the file?

Show the steps and the answer
Answer

{name}: {length:.2f} m

Why: The opening quote has no f before it, so the text inside the quotes appears as typed. The line ends with a newline.

Source: Python Software Foundation, Python 3.13 Tutorial, Formatted String Literals

Quick check 2 of 2

Use the supplied values name = "Elm" and length = 2.3125 in the editor. Use the original print line with its f prefix. What line appears in the shell when you run the file?

Show the steps and the answer
Answer

Elm: 2.31 m

Why: The third digit after the decimal point is 2, so rounding to two places keeps 1 as the second digit, in the hundredths place. The line ends with a newline.

Source: Python Software Foundation, Python 3.13 Tutorial, Formatted String Literals

Sources

  1. Python 3.13 Tutorial, Formatted String Literals. Python Software Foundation. Python Software Foundation License Version 2. Read 26 Nov 2026.