Solve one- and two-step linear equations with inverse operations, and check every answer.
Why this matters
Many practical questions are really "find the missing number" problems. How many months until savings reach a target? What current gives a certain voltage drop? How many servers handle a given load? Each one becomes a linear equation, and solving it is a short, reliable routine.
The core idea: keep the balance
An equation says two expressions are equal, like a balanced scale: 3x + 5 = 20. You may do anything you like to one side as long as you do the same thing to the other side. The goal is to get the variable alone (isolate it).
To isolate the variable, undo what has been done to it using inverse operations:
- addition ↔ subtraction
- multiplication ↔ division
Undo in the reverse order of operations: deal with added or subtracted numbers first, then multiplied or divided ones.
Worked example 1: one step
x − 7 = 12
Add 7 to both sides: x = 19.
Check: 19 − 7 = 12. (checks out)
Worked example 2: two steps
3x + 5 = 20
- Subtract 5 from both sides: 3x = 15
- Divide both sides by 3: x = 5
Check: 3(5) + 5 = 20. (checks out)
Worked example 3: negative coefficient
−4x + 6 = −10
- Subtract 6: −4x = −16
- Divide by −4: x = 4
Check: −4(4) + 6 = −16 + 6 = −10. (checks out)
Dividing by a negative is fine in equations. (It only flips the sign in inequalities, such as < and >.)
Worked example 4: variables on both sides
5x − 3 = 2x + 9
- Subtract 2x from both sides: 3x − 3 = 9
- Add 3: 3x = 12
- Divide by 3: x = 4
Check: left 5(4) − 3 = 17, right 2(4) + 9 = 17. (checks out)
Worked example 5: a word problem
A freelancer charges a $40 call-out fee plus $55 per hour. An invoice is $315. How many hours?
- Name the unknown: h = hours.
- Write the equation: 40 + 55h = 315
- Subtract 40: 55h = 275
- Divide by 55: h = 5
Answer: 5 hours. Check: 40 + 55 × 5 = 315. (checks out)
A general formula
Every equation of the form ax + b = c (with a not zero) is solved the same way:
x = (c − b) / a
That is just the two-step routine written once. Code can use it directly:
def solve_linear(a, b, c):
return (c - b) / a
x = solve_linear(3, 5, 20)
print(x) # 5.0
print(3 * x + 5 == 20) # True: always check
If a = 0 there is no x to solve for: the equation is either always true (b = c) or never true. Real code should handle that case instead of dividing by zero.
Why checking matters
Substituting your answer back into the original equation takes seconds and catches sign errors, arithmetic slips and setup mistakes. In professional work, an unchecked answer is a guess. Make the check a habit, not an extra.
Common mistakes
- Doing an operation to one side only. Every step must apply to both sides.
- Undoing in the wrong order, such as dividing by 3 before subtracting 5 in 3x + 5 = 20 (possible, but you must divide every term: x + 5/3 = 20/3).
- Losing a negative sign when moving terms. Write out each step rather than "moving" terms in your head.
- Checking against your rewritten equation instead of the original one.
Quick recap
- Do the same operation to both sides to keep the balance.
- Undo addition/subtraction first, then multiplication/division.
- For ax + b = c: x = (c − b) / a, provided a ≠ 0.
- Always substitute back into the original equation.
Try it
In the Do tab, write the one-line formula inside solve_linear and let the checks confirm it works for positive, negative and fractional answers.