Math Expressions Lesson

1. LxD Cycle Process

Empathize: We noticed that students learning basic Python math expressions often get overwhelmed and confused when we wrap basic arithmetic in long, multi-step storylines, creating unnecessary cognitive load before they even grasp the core syntax.

Define:

  • POV: CSP students need a streamlined way to practice Python operators and variables without confusing storylines because wrapping basic math in unrelated themes creates unnecessary cognitive load.
  • Learning Goal: Students will understand how to assign values to variables and use Python arithmetic operators (+, -, *, /) with clean, straightforward examples.

Ideate:

  • HMW Question: How might we teach Python math expressions cleanly without distracting stories or overly complex themes?
  • Activity: A direct, theme-free code walkthrough using value_a and value_b, paired with a straightforward currency conversion homework task.

Prototype & Test: We originally drafted lessons with multi-step real-world themes, but feedback showed students preferred a clean, distraction-free structure. We streamlined the lesson to focus strictly on foundational operators.

2. Lesson Plan

Learning Objective: By the end of this lesson, you will be able to write dynamic math expressions using Python operators so your program automatically calculates outputs based on variable inputs for the Poway Recovery Center platform.

Success Criteria: You can take raw numbers for session capacity and group bookings, assign them to variables, apply the correct arithmetic operators, and print the evaluated result.

Tech Talk (3 minutes) When building the Poway Recovery Center website, you need code that can handle real-time user bookings. This means you don’t need to do the math yourself. Instead of figuring out remaining slots and typing them in, you tell the computer how to calculate it using variables and operators.

The Rule: Use variables and operators. Let Python handle the evaluation.

  • βœ… Do this: remaining_capacity = total_capacity - (group_size * sessions) followed by print(remaining_capacity)
  • ❌ Don’t do this: print("There are 88 spots left")

Why do we do this? It ensures our platform updates dynamically when users book sessions, makes our code reusable, and powers real-world app features.

LESSON

Part 1 β€” The Basics: What is a Math Expression?

Why this matters: Every program that calculates a price, a score, a distance, or a time is built on math expressions. A math expression combines numbers and operators so the computer evaluates them into a single new value β€” without expressions, a program can only store numbers, it can never actually do anything with them.

Python uses the same basic operators as a calculator:

Operator Meaning Description Usage Example
+ Addition Adds two values together. 10 + 5 evaluates to 15
- Subtraction Subtracts the second value from the first. 10 - 5 evaluates to 5
* Multiplication Multiplies two values. 10 * 5 evaluates to 50
/ Division Divides the first value by the second. 10 / 5 evaluates to 2.0
** Exponentiation Raises the first value to the power of the second. 2 ** 3 evaluates to 8
// Floor Division Divides and rounds down to the nearest whole number. 10 // 3 evaluates to 3
% Modulus Divides and returns only the remainder. 10 % 3 evaluates to 1

Setting Up Your Environment

For these two popcorn hacks, as well as the homework, you’ll work in your own portfolio repository instead of this shared lesson.

How to Create a New Notebook in Your Portfolio

1. Open your portfolio repository in VS Code (or your editor of choice).
2. Inside your _notebooks folder, create a new file: YYYY-MM-DD-math-expressions-hw.ipynb.
3. Add a raw/markdown cell at the top with the frontmatter provided. OR Copy paste this file into your portfolio and change frontmatter accordingly. ➑️
---
layout: post
categories: [Python, Mathematical-Expressions]
lesson_language: Python
lesson_topic: Mathematical-Expressions
lesson_part: interactive
lesson_type: lesson
title: 3.3 Math Expressions HW
permalink: /csp/python/math-expressions/hw
Authors: YourName
---
4. Add a code cell for each task below and write your Python math expressions there. Make sure to title each section using a Markdown block (i.e. Popcorn Hack 1, Popcorn Hack 2, HW).
5. Run each cell (β–Ά Run or Shift+Enter) to check your output before moving on.
6. Commit and push your notebook, then confirm it builds on your portfolio site.

Popcorn Hack 1: Try the Basics

Fill in the TODOs below using the operators you just learned, then press Run to check your results.

Code Runner Challenge

Popcorn Hack - Basic Arithmetic Operators

View IPYNB Source
# CODE_RUNNER: Popcorn Hack - Basic Arithmetic Operators
value_a = 100
value_b = 10
value_c = 25

# TODO: calculate total of A, B, and C using the variables above
addition = 0  # Replace with your expression (e.g., value_a + value_b + value_c)

# TODO: calculate the difference between items A and B using the variables above
subtraction = 0  # Replace with your expression

# TODO: calculate the product of items B and C using the variables above
multiplication = 0  # Replace with your expression

# TODO: divide value A by value B and output the division using the variables above
division = 0  # Replace with your expression

print("Total:", addition)
print("Difference:", subtraction)
print("Product:", multiplication)
print("Division:", division)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Going Deeper: Mathematical Expressions

Most expressions you write use infix notation β€” the operator sits between the numbers, like 5 + 3. Computers don’t have to evaluate math that way.

RPN removes the need for parentheses and order-of-operations rules β€” every expression can be evaluated left to right using an algorithm. Create a data structure stack (like plates), first-in, first-out.

Step Input Queue Operation Stack
1 5 3 - 2 * Push 5 [5]
2 3 - 2 * Push 3 [5, 3]
3 - 2 * Pop 3, pop 5 β†’ 5 - 3 β†’ push 2 [2]
4 2 * Push 2 [2, 2]
5 * Pop 2, pop 2 β†’ 2 Γ— 2 β†’ push 4 [4]
6 (empty) Result [4]

This is important as we often think the human representation of a problem is simple, but computer algorithms are required behind the scenes for everything we do on computers. RPN is still used today in some scientific and financial calculators because it’s fast and never ambiguous.

Popcorn Hack 2: Project Based Math-Expression Hack

The significance of the Popcorn hack is that it teaches you how to write code that actually scales. Instead of hardcoding numbers into the print statement messages, you learn to use variables so features like the Poway Recovery Center booking system can automatically update and calculate data in real time.

In your new notebook, add a code cell and use math expressions to calculate the weekly and monthly cost of attending sessions at a recovery center.

Given:

  • cost_per_session = 35
  • sessions_per_week = 3
  • weeks_per_month = 4

Calculate and print:

  1. weekly_cost β€” cost per session Γ— sessions per week
  2. monthly_cost β€” weekly cost Γ— weeks per month

To help aid your understanding, we have provided a COMPLETED popcorn hack in Pseudocode so that it may help you in writing the Python code.

Run your cell to confirm the output before moving on to the homework below.

Code Runner Challenge

Pseudocode Template (COMPLETED EXAMPLE) of Popcorn Hack 2

View IPYNB Source
# CODE_RUNNER: Pseudocode Template (COMPLETED EXAMPLE) of Popcorn Hack 2

total_monthly_capacity ← 100
spots_requested_per_group ← 4
sessions_booked ← 3

// 1. Multiplication: total spots taken by the booking group
total_spots_taken ← spots_requested_per_group * sessions_booked

// 2. Subtraction: remaining capacity for the center
remaining_capacity ← total_monthly_capacity - total_spots_taken

// 3. Division: distribute remaining spots evenly across 2 rooms
users_per_room ← remaining_capacity / 2

DISPLAY("Total Spots Taken: " + total_spots_taken)
DISPLAY("Remaining Capacity: " + remaining_capacity)
DISPLAY("Users per Room: " + users_per_room)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Code Runner Challenge

Python Version of Popcorn Hack 2

View IPYNB Source
# CODE_RUNNER: Python Version of Popcorn Hack 2

# Grouping operations for the Poway Recovery Center booking system
total_monthly_capacity = 100
spots_requested_per_group = 4
sessions_booked = 3

# 1. Multiplication: Calculate total spots taken by the booking group
# PUT YOUR CODE HERE

# 2. Subtraction: Calculate remaining capacity for the center
# PUT YOUR CODE HERE

# 3. Division: Distribute remaining spots evenly across 2 active rooms
# PUT YOUR CODE HERE

# Print the final outputs - EDIT THE CODE BELOW
print("Total Spots Taken: ", )
print("Remaining Capacity ", )
print("Users per Room: ", )
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

AP CSP Practice Questions: Variables & Mathematical Expressions

1. Consider the following code segment:

Code Runner Challenge

HOMEWORK

View IPYNB Source
a ← 4
b ← 6
c ← 2
a ← b + c
b ← a - c
c ← a + b
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

What are the final values of a, b, and c after this code segment is executed? A) a = 4, b = 6, c = 2 B) a = 8, b = 6, c = 14 C) a = 8, b = 4, c = 12 D) a = 8, b = 8, c = 16

2. Consider the following expression:

result ← 10 + 17 MOD 5 * 2

According to the standard order of operations used in AP CSP, what value is stored in result? A) 14 B) 16 C) 10 D) 20

3. In the AP CSP pseudo-code, which of the following expressions evaluates to 3.5? A) 7 MOD 2 + 2 B) 7 / 2 C) 14 MOD 4 / 2 D) 3 + 1 / 2 * 0


Answer Key & Explanations

1. Answer: B (a = 8, b = 6, c = 14)

  • a ← 4, b ← 6, c ← 2 (Initial values)
  • a ← b + c (a becomes 6 + 2 = 8)
  • b ← a - c (b becomes 8 - 2 = 6)
  • c ← a + b (c becomes 8 + 6 = 14)

2. Answer: A (14)

  • According to the AP CSP reference sheet, MOD, *, and / have the same precedence and are evaluated left to right before addition +.
  • Step 1: 17 MOD 5 evaluates to 2 (the remainder of 17 divided by 5).
  • Step 2: 2 * 2 evaluates to 4.
  • Step 3: 10 + 4 evaluates to 14.

3. Answer: B (7 / 2)

  • Unlike AP CSA where 7 / 2 would truncate to the integer 3, AP CSP evaluates division to an exact decimal. Therefore, 7 / 2 evaluates exactly to 3.5.

πŸ“ Homework (10 Minutes): Recovery Center Cost Report

In the same portfolio notebook, add new code cell below your interactive task and build a full cost report.

Given:

  • cost_per_session = 35
  • sessions_per_week = 3
  • weeks_per_month = 4
  • enrollment_fee = 75 (one-time cost)

Calculate and print each of the following:

  1. weekly_cost β€” cost per session Γ— sessions per week
  2. monthly_cost β€” weekly cost Γ— weeks per month
  3. total_cost_with_fee β€” monthly cost plus the one-time enrollment fee
  4. average_daily_cost β€” monthly cost divided by 30

Commit and push your notebook when you’re done β€” you’ll link it in the submission form below.

# CODE_RUNNER: HOMEWORK

# Recovery Center Cost Report

cost_per_session = 35
sessions_per_week = 3
weeks_per_month = 4
enrollment_fee = 75

# 1. Calculate weekly cost


# 2. Calculate monthly cost


# 3. Calculate total cost with fee


# 4. Calculate average daily cost


# Print all results with labels
print("Weekly Cost: ", )
print("Monthly Cost: ", )
print("Total Cost with Fee: ", )
print("Average Daily Cost: ", )

References

AP CSA Unit 1, Topic 1.3 Expressions and Assignment Statements. Quoted from the course and exam description (College Board, 2025, p. 34):

1.3.A.1 β€œThe arithmetic operators consist of addition (+), subtraction (-), multiplication (*), division (/), and modulus (%).”

1.3.B.1 β€œAn arithmetic expression consisting only of int operands evaluates to an int result; the portion of the quotient representing the fractional part is truncated.”

1.3.B.2 β€œAn arithmetic expression involving at least one double operand evaluates to a double result.”

1.3.C.1 β€œArithmetic expressions can be evaluated using the standard order of operations.”

1.3.D.1 β€œThe assignment operator (=) allows a program to initialize or change the value stored in a variable. The value of the expression on the right is stored in the variable on the left.”

The College Board also says β€œthe use of the modulo operator (%) with negative operands is outside the scope of the course and exam” (College Board, 2025, p. 34). This lesson still covers it because it is handy in real code, but it will not be on the exam.

πŸ“Š Grading Plan

Grading Plan β€” 1.0 Total
0.2 β€” PH1: Correct Popcorn Hack 1 (Basic Arithmetic Operators Hack)
0.2 β€” PH2: Correct Popcorn Hack 2 (PRC Calculations Hack)
0.2 β€” Homework: Correct weekly_cost and monthly_cost expression
0.2 β€” Homework: Correct total_cost_with_fee and average_daily_cost expression
0.2 β€” All code runs without errors and every result is printed with a label

πŸ“€ Submit Your Homework

Once your notebook is committed and pushed, submit your portfolio link using the form below.

Submit Homework β†’

Submit Assignment

Self-Assessment

Rate your work on this assignment, then add a short reflection. All 5 fields are required before you can submit.

Technical Excellence

Rate the technical quality of your work on this assignment β€” your use of tools, problem-solving, and technical growth.

1 Explore · 2 Understand · 3 Apply · 4 Analyze/Evaluate · 5 Create/Extend
Communication

Rate how clearly you communicated your work and process β€” explanations, documentation, and collaboration or help-seeking.

1 Beginning · 2 Developing · 3 Consistent · 4 Strong · 5 Model
Work Habits

Rate your work habits on this assignment β€” time management, persistence, responsibility, and follow-through.

1 Beginning · 2 Developing · 3 Consistent · 4 Strong · 5 Model
AI Orchestration

Rate how effectively you used AI tools to support your work β€” prompting, verifying, extending, or accelerating your development process.

1 Explore · 2 Understand · 3 Apply · 4 Analyze/Evaluate · 5 Create/Extend

Need to update a submission later? Open the submissions dashboard.