3.3 — Math Expressions

Sequencing, Selection, Iteration, and Arithmetic Operations.

Learning Objectives

  • Express an algorithm that uses sequencing without a programming language.
  • Represent a step-by-step algorithmic process using sequential code statements.
  • Evaluate expressions that use arithmetic operators.

What is an Algorithm?

An algorithm is a finite set of instructions that accomplish a specific task.

Key concepts:

  • Sequencing: first step → second step → third step
  • Selection: decision-making (yes/no) → different steps depending on outcome
  • Iteration: repeat steps until a condition is met

Example Algorithm: Count Even Numbers in a List

  1. Set count ← 0
  2. Get next number from the user
  3. check if its even, if yes then count ← count + 1
  4. If more numbers in list, go back to Step 2
  5. Display count

Sequencing: Steps 1 → 2 → 3 → 4 → 5

Selection: Step 3 (even or odd decision)

Iteration: Step 4 (loop until list exhausted)

💡 Hack 1: Identify Sequencing, Selection, and Iteration

Analyze the following algorithm and identify which parts demonstrate sequencing, selection, and iteration:

  1. Set item to the number to search for
  2. Get next number in the list
  3. If number = item, display “item found”
  4. If there are more numbers in the list, go back to Step 2
  5. Display “item not found”

Code Statements & Expressions

Store values in variables and compute results:

Grade ← 82
highScore ← currentScore
Name ← firstName + lastName
Average ← calcAverage(10, 20, 30)

Hack 2: Predict the Output

Identify what is displayed after running the following code segment:

num1 ← 2
num2 ← 4
num3 ← 5
num1 ← num2 + num3
num3 ← num1 + 5
num2 ← (num1 + num3) / 5
DISPLAY(num1)
DISPLAY(num2)
DISPLAY(num3)

Hints / Thought Process:

  • Step 1: Track how num1, num2, and num3 change at each line.
  • Step 2: Apply arithmetic operations carefully and in order.
  • Step 3: Remember that assignment updates the variable immediately.

Arithmetic Operators & Order of Operations

+  addition (a + b, grade + 10)
-  subtraction (a - b, 100 - pointsDeducted)
*  multiplication (a * b, base * height)
/  division  (a / b, sum / 28)
MOD  modulus (remainder) (a MOD b, 17 MOD 2)

note: Python MOD is %

Hack 3: Practice

Predict the value of result after executing the code:

num1 ← 40
num2 ← num1 / 2
num3 ← 5 * num2 + 3
result ← num2 MOD 3 * num1 + 4 - num3 / 2
DISPLAY(result)

🎮 Flappy Math — Expressions

Fly through 10 gates. Each gate asks a tiny math/code question. Answer right to keep going! Click game or press F for fullscreen.

Score: 0 / 10
Press Space / click / tap to flap • F to toggle fullscreen

Checkpoint

You Win!

Click / tap to flap. Pass a pipe ➜ answer a quick expression question. Get to 10!

Tip: please don't use full screen! PRESS SPACE BAR FIRST, THEN CLICK START TO START THE GAME