Variables, Expressions, and Algebra as a Superpower
Translate word problems into equations, solve them by hand, and build a Python equation solver.
Materials for this lesson
- Laptop (charged)
- Whiteboard and markers
Warm-Up: Mental Math Sprint
Solve each of these in your head using the distributive property. Time yourself — can you finish all six in under 90 seconds?
6 × 14(think: 6 × 10 + 6 × 4)8 × 257 × 98(hint: 7 × 100 - 7 × 2)12 × 1599 × 625 × 32
The distributive property says a × (b + c) = a × b + a × c. This isn't just a math rule — it's a mental math superpower. Professional mental calculators use tricks like this constantly. Notice how problem 3 is much easier if you think of 98 as (100 - 2).
Core Lesson: Algebra — The Language of Problem Solving
What Is a Variable?
In math, a variable is a letter that stands for an unknown number. You've already been using this idea — when you saw ___ in a sequence last week, that blank was acting as a variable.
But variables aren't just blanks. They're the foundation of algebra, which is arguably the most powerful tool in all of mathematics. Algebra lets you take a messy real-world problem and turn it into a clean equation you can solve.
A variable is a symbol (usually a letter like x, n, or t) that represents a quantity we don't know yet. An expression is a combination of numbers, variables, and operations (like 3x + 7). An equation says that two expressions are equal (like 3x + 7 = 22).
Translating Words into Math
The hardest part of algebra isn't solving the equation — it's setting it up. Here's a cheat sheet for translating English into math:
| English Phrase | Math Operation | Example |
|---|---|---|
| "more than," "increased by," "total" | Addition (+) | "5 more than x" → x + 5 |
| "less than," "decreased by," "fewer" | Subtraction (-) | "7 less than x" → x - 7 |
| "times," "of," "product" | Multiplication (×) | "triple x" → 3x |
| "per," "divided by," "split among" | Division (÷) | "x split among 4" → x / 4 |
| "is," "equals," "gives," "results in" | Equals (=) | "x plus 3 is 10" → x + 3 = 10 |
Practice: Translate these sentences into equations:
- "A number doubled, plus five, equals seventeen."
- "If you subtract eight from three times a number, you get thirteen."
- "The total cost of n shirts at $12 each, plus $5 shipping, is $65."
Solving Single-Variable Equations
Solving an equation means isolating the variable — getting x by itself on one side. The golden rule:
Whatever you do to one side, you must do to the other.
Let's solve 3x - 8 = 13 step by step:
| Step | Action | Result |
|------|--------|--------|
| Start | — | 3x - 8 = 13 |
| Add 8 to both sides | Undo the subtraction | 3x = 21 |
| Divide both sides by 3 | Undo the multiplication | x = 7 |
| Check: 3(7) - 8 = 21 - 8 = 13 | Verified! | |
Solve for x: 5x + 3 = 28
The Distance = Rate × Time Formula
One of the most useful equations in all of science:
d = r × t (Distance = Rate × Time)
This single formula connects three quantities. If you know any two, you can find the third:
- d = r × t — How far did it go?
- r = d / t — How fast was it going?
- t = d / r — How long did it take?
Example: A car travels at 60 mph for 2.5 hours. How far does it go?
d = 60 × 2.5 = 150 miles
Example: A runner covers 10 km in 50 minutes. What is their speed?
r = 10 / 50 = 0.2 km/min = 12 km/hr
A plane flies 2,400 miles at 600 mph. How long does the flight take?
Algebra Basics: What Is Algebra? — Math Antics
Hands-On Lab: Build a Python Equation Solver
We're going to write a program that solves equations of the form ax + b = c, where the user provides a, b, and c.
Program 1: Basic Equation Solver
# Solve ax + b = c for x
print("=== Equation Solver ===")
print("I'll solve equations of the form: ax + b = c\n")
a = float(input("Enter a (the coefficient of x): "))
b = float(input("Enter b (the constant added to x): "))
c = float(input("Enter c (what it equals): "))
if a == 0:
if b == c:
print("Every number is a solution! (The equation is always true.)")
else:
print("No solution! (The equation is never true.)")
else:
x = (c - b) / a
print(f"\nSolving: {a}x + {b} = {c}")
print(f"Step 1: {a}x = {c} - {b} = {c - b}")
print(f"Step 2: x = {c - b} / {a} = {x}")
print(f"\nAnswer: x = {x}")
# Verify the answer
check = a * x + b
print(f"\nCheck: {a} × {x} + {b} = {check} ✓" if check == c else f"\nCheck failed!")
Test it with: a = 3, b = -8, c = 13 — you should get x = 7.
Program 2: Distance-Rate-Time Calculator
# Distance-Rate-Time solver
print("=== Distance-Rate-Time Calculator ===")
print("d = r × t")
print()
print("What do you want to find?")
print("1. Distance (I know rate and time)")
print("2. Rate (I know distance and time)")
print("3. Time (I know distance and rate)")
choice = input("\nYour choice (1, 2, or 3): ")
if choice == "1":
r = float(input("Enter rate (speed): "))
t = float(input("Enter time: "))
d = r * t
print(f"\nDistance = {r} × {t} = {d}")
elif choice == "2":
d = float(input("Enter distance: "))
t = float(input("Enter time: "))
if t == 0:
print("Error: time cannot be zero!")
else:
r = d / t
print(f"\nRate = {d} / {t} = {r}")
elif choice == "3":
d = float(input("Enter distance: "))
r = float(input("Enter rate (speed): "))
if r == 0:
print("Error: rate cannot be zero!")
else:
t = d / r
print(f"\nTime = {d} / {r} = {t}")
else:
print("Invalid choice!")
Program 3: Word Problem Translator
This program walks through a word problem step by step:
# Shirt problem: 12n + 5 = budget
print("=== T-Shirt Budget Problem ===")
print("Each shirt costs $12. Shipping is $5.\n")
budget = float(input("What is your total budget? $"))
# Solve: 12n + 5 = budget → n = (budget - 5) / 12
if budget < 5:
print("You can't even afford shipping!")
else:
n_exact = (budget - 5) / 12
n_whole = int(n_exact) # Can only buy whole shirts!
leftover = budget - (12 * n_whole + 5)
print(f"\nEquation: 12n + 5 = {budget}")
print(f"12n = {budget - 5}")
print(f"n = {n_exact:.2f}")
print(f"\nYou can buy {n_whole} shirt(s).")
print(f"Total cost: ${12 * n_whole + 5:.2f}")
print(f"Money left over: ${leftover:.2f}")
New Python concepts:
float()— converts text to a decimal number (not just whole numbers likeint()):.2fin f-strings — formats a number to exactly 2 decimal places (great for money!)int()on a float — drops the decimal part (truncates), useful when you need whole numbers
Challenge: The Classic Train Problem
Two trains leave different cities heading toward each other. City A and City B are 360 miles apart.
- Train A leaves City A heading east at 80 mph.
- Train B leaves City B heading west at 100 mph.
- They leave at the same time.
Part 1: How long until the trains meet? Solve by hand using algebra.
Hint: If Train A travels a distance d₁ and Train B travels d₂, then d₁ + d₂ = 360. Use d = r × t, and remember they travel for the same amount of time.
Part 2: Write a Python program to verify your answer. Bonus: Make the program animate the trains approaching each other.
Extra challenge: What if Train B leaves 30 minutes after Train A? Now when and where do they meet? Set up the equation, solve by hand, then modify the code to check.
Resources
- Khan Academy: Intro to Variables — clear video lessons on variables and expressions
- Python Basics — W3Schools — reference for Python syntax
- Replit — online code editor
- Math is Fun: Algebra — great reference for equation-solving techniques
- Distance, Rate, Time Problems — Purplemath — more practice with d = r × t problems