Skip to main content
AP CSP course

C21 · Topic 3.3 · 40 minutes · AAP-2.A, AAP-2.B, AAP-2.C

Expressions and arithmetic

By the end you can:

  • Apply precedence and parentheses.
  • Calculate a positive-integer remainder.
  • Distinguish numerical arithmetic from text concatenation.

Before this lesson: topics 3.1.

Expression
A combination of values and operators evaluated to produce a value.
MOD
The remainder operation; for positive integers a and b,a MOD b is the remainder on division byb.

Understand

Arithmetic expressions are evaluated by the stated operator precedence. In AP CSP, multiplication, division and MOD take precedence over addition/subtraction; operations at the same precedence are evaluated left to right. Parentheses can deliberately change the grouping, so show intermediate values rather than reading purely left to right.

For positive integers, a MOD b gives a remainder from 0 through b−1 when b is positive. It is not the quotient and is not a percentage operator. A number-like string is still text under a text operation; do not silently turn concatenation into numerical addition.

Worked example

Evaluate(4+2*9)MOD 5.

  1. Multiplication gives 18.
  2. The parenthesised sum is 22.
  3. 22=4*5+2, so the remainder is 2.

Explore each concept

Choose a concept, change its inputs and follow the explanation. Each example models the stated rule or scenario; completing it is practice rather than evidence of mastery.

  • Arithmetic precedence
  • Parentheses and reordering
  • Numeric addition versus concatenation
Open this example on its own

Change it · step through · explain

Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.

Ready · Make a prediction

Ready to explore: Precedence, division, MOD and sequencing
  1. a (0–100)4Waiting
  2. b (1–100)5Waiting
  3. Expressiona+2*bWaiting

Ready to explore: Precedence, division, MOD and sequencing

Why: Change an input, predict the first effect, then advance one step.

Try this: Change one input or choose another listed case. Predict the effect, reset and compare the states and governing rule.

Step through and experiment

Change it · step through · explain

Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.

Ready · Make a prediction

Ready to experiment
  1. Input 14Waiting
  2. Input 29Waiting
  3. Input 35Waiting

Ready to experiment

Why: Predict the first change, then advance one step.

Try this: Change one input, predict the difference, then reset and compare.

Check a misconception

Claim: MOD returns the quotient of a division.

It returns the remainder;22 divided by 5 has quotient 4 and remainder 2.

Guided practice

Evaluate 7+8 MOD 3*2 using the AP precedence convention.

Work with a partner. Make a prediction, compare your reasoning, then identify the rule that supports your answer.

Independent transfer

Choose parentheses that make 3+4*2 produce 14 instead of 11.

Exit check

Why is RANDOM(1,6)not part of a pure fixed arithmetic prediction without further information?

Write your reasoning before comparing with a classmate. If your teacher assigned this task, submit it through My classes to save your work and receive feedback.

Check yourself

  1. Question 1 of 2What is19MOD4?

    Select one answer.

  2. Question 2 of 2What is8+3*4?

    Select one answer.

Your practice so far

Check an answer to see its rationale.

Teacher guidance and scoring