Type on any line or blank, or switch Draw on to write with a finger, stylus or mouse. Your work is saved in this browser on this device only. Nothing is sent anywhere. The answer key after page 2 stays covered until you open it, and it never prints with your work: it has its own print button.

Practice sheet · Coding & AI Path · Lens 1: Math

Binary & logic

Practice for The Math of Coding & AI: binary, variables, loops, logic, probability, accuracy, coordinates and algorithms (pp.8–16), plus Algebra A1–A2 (pp.17–18).
Warm-upCoreLevel Up
Name Date Time I spent
Remember

Binary place values (right to left): 1, 2, 4, 8, 16, 32… n bits store 2ⁿ values. x = x × 3 means “take x, triple it, store it back.”

and needs both sides true; or needs at least one. Accuracy = right ÷ total. Halving a list each guess (binary search) takes about log₂(n) guesses.

Warm-up

One step

Binary, variables and logic.
1

Binary

Convert binary 10110 to a normal number. Write 25 in binary.

2

Trace it

x = 7, then x = x × 3, then x = x − 4. What is x at the end?

3

True or False

score = 8 and lives = 2. Is score ≥ 10 or lives > 1 True? What if the or is an and?

4

Bits

How many different values can 4 bits store? 10 bits?

Core

Two or three steps

Trace the code line by line.
5

Loop sum

A loop adds 1 + 2 + … + 200. What is the total? for i in range(5, 15) runs how many times, and what do its i values add up to?

6

Chance

What is the chance two dice add to 7? That 3 coin flips are all heads?

Coding Practice · Coding & AI Path · Unizon1/2
Coding & AI Path · Unizon · PracticeBinary, logic & algorithms
7

Lazy filter

200 emails; 20 are spam. A filter that never says “spam” is how accurate? A better one catches 18 spam but flags 6 good emails. How accurate is it?

8

Average trap

App load times: 4, 6, 6, 8 and 31 seconds. Find the mean and median. Which describes a typical load better?

9

Move the sprite

A Scratch sprite is at (−120, 60). It changes x by 50 and y by −90. Where is it now?

10

Guess my number

Binary search halves the range each guess. How many guesses at most for 1 to 500? For 1 to 1,000,000?

Level Up

Equations

A1–A2 (pp.17–18).
11

One sprite

A sprite starts at x = −180 and moves 12 steps a frame: x = −180 + 12t. On which frame does it reach x = 120?

12

Two sprites

Sprite B starts at x = 200 and moves −7 a frame: x = 200 − 7t. When and where do the sprites meet?

13

Jump

A jump follows y = −t² + 12t. When does it land? How high is the top? When is it at height 20?

14

Pairs

Comparing every pair of n items takes n(n − 1) ÷ 2 checks. If it took 66 checks, find n. How many checks for 20 items?

Make your own problem

Your turn to be the game programmer

  1. Pick a game or app you use.
  2. Write a question about its bits, loops, chances or coordinates.
  3. Solve it, then trace it line by line like a computer would.

My problem, and my worked answer:

Coding Practice · Coding & AI Path · Unizon2/2
Coding & AI Path · Unizon · PracticeBinary, logic & algorithms

Try every problem first, then check here. Wrong answers are useful: find the step where your work and the key split apart.

The key never prints with Print my work or Print blank. Open it to get its own Print the answer key button.

Answer key

Worked solutions. Emails and load times are made-up examples.

Warm-up
1
22 · 11001 16 + 4 + 2 = 22. 25 = 16 + 8 + 1 → 11001.
2
17 7 × 3 = 21; 21 − 4 = 17.
3
True · False lives > 1 is True, so or is True. score ≥ 10 is False, so and is False.
4
16 · 1,024 2⁴ = 16; 2¹⁰ = 1,024.
Core
5
20,100 · 10 times · 95 200 × 201 ÷ 2 = 20,100. range(5, 15) is 5 to 14: 10 values, sum 95.
6
1/6 ≈ 0.167 · 1/8 = 0.125 6 of the 36 rolls add to 7. ½ × ½ × ½ = 1/8.
7
90% · 96% 180 ÷ 200 = 90%, yet it catches no spam. Right = 18 + (180 − 6) = 192; 192 ÷ 200 = 96%.
8
mean 11 · median 6 55 ÷ 5 = 11. One slow load (31) drags the mean up; the median, 6, is more typical.
9
(−70, −30) −120 + 50 = −70; 60 − 90 = −30.
10
9 · 20 2⁹ = 512 ≥ 500. 2²⁰ = 1,048,576 ≥ 1,000,000.
Level Up
11
frame 25 12t = 300 → t = 25.
12
frame 20 · x = 60 −180 + 12t = 200 − 7t → 19t = 380 → t = 20; x = −180 + 240 = 60.
13
lands at 12 · top 36 · t = 2 and 10 t(12 − t) = 0 → t = 12. Top at t = 6: 36. t² − 12t + 20 = 0 → (t − 2)(t − 10) = 0.
14
n = 12 · 190 n(n − 1) = 132 = 12 × 11. 20 × 19 ÷ 2 = 190.
Make your own: trace code one line at a time, write each variable’s new value, and check what “accuracy” is hiding.
Coding Practice · Coding & AI Path · UnizonAnswer key