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

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 = value_a + value_b + value_c  # 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 = value_a - value_b  # Replace with your expression

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

# TODO: divide value A by value B and output the division using the variables above
division = value_a / value_b  # 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
# NOTE: This cell is pseudocode for reference only, not runnable Python.
# Every line below is commented out so this cell can still be run harmlessly.

# 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
total_spots_taken = spots_requested_per_group * sessions_booked

# 2. Subtraction: Calculate remaining capacity for the center
remaining_capacity = total_monthly_capacity - total_spots_taken

# 3. Division: Distribute remaining spots evenly across 2 active rooms
users_per_room = remaining_capacity / 2

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

📝 Homework (10 Minutes): Recovery Center Cost Report

In the same portfolio notebook, add a 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 Challenge

HOMEWORK

View IPYNB Source
# 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
Weekly_Cost = cost_per_session * sessions_per_week

# 2. Calculate monthly cost
Monthly_Cost = Weekly_Cost * weeks_per_month

# 3. Calculate total cost with fee
Total_Cost_with_Fee = Monthly_Cost + enrollment_fee


# 4. Calculate average daily cost
Average_Daily_Cost = Total_Cost_with_Fee / (weeks_per_month * 7)


# Print all results with labels
print("Weekly Cost: ", Weekly_Cost)
print("Monthly Cost: ", Monthly_Cost)
print("Total Cost with Fee: ", Total_Cost_with_Fee)
print("Average Daily Cost: ", Average_Daily_Cost)
# Won't explain because they are mathematical concepts :)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

📊 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 →