Skip to lesson content

Math / Algebra / Lesson 1

Algebra · Learn and experiment

What goes into a delivery bill?

Your outcome: Turn a pricing question into an equation, then use it to find an unknown distance.

Lesson 1 of 6

Variables and equations

Start here: a variable gives us a short name for a quantity; an equation keeps the relationship while the numbers change.

An equation turns a bill into a question

A book costs ₹120 and each notebook costs ₹35. Your bill is ₹330. Instead of guessing notebook counts, give the unknown a name: n. The equation records the story; solving it finds a value that makes the story true.

Pause and predict

Would six notebooks fit the bill? What must stay equal when you subtract the book price?

Need a quick refresher?

Multiplication happens before addition. The equals sign compares values; it is not an instruction to keep calculating.

The full story · about 12 minutes

A bill you can write down, and run backwards

1 · Observe

A delivery app and an unexplained bill

Words used in this lesson
WordWhat it means
EquationTwo things joined by an equals sign, claiming they have the same value.
UnknownThe number you are trying to find, usually called x.
ParameterA number in the rule that is fixed for now, such as the ₹40 starting fee.
Inverse (undo)Reversing a rule's steps, in the opposite order.
SubstitutePutting a number in place of x to check it.

A delivery app charges ₹40 to start and ₹12 for every kilometre. Rahul sees a bill of ₹160 and wonders how far the rider went. He could guess and check, but there is a faster way: write the rule as an equation and run it backwards.

This is the oldest trick in mathematics, and the first one machine learning uses. A model is a rule with some numbers in it. Learning is finding the numbers that make the rule match the world.

2 · Express

Naming the unknown

Let x be the distance in kilometres. The bill is the fixed fee plus the rate times x. The ₹40 and the ₹12 are parameters: numbers we set and hold still while x varies. The 12 multiplying x is a coefficient.

bill = 40 + 12 x
40 + 12 x = 160 ← an equation: two expressions that must be equal
An expression describes a calculation. An equation says two expressions are equal, and solving it means finding the x that makes that true.

3 · Visualize

Undo in reverse order

The bill was built by multiplying x by 12, then adding 40. To undo, reverse the order: subtract 40 first, then divide by 12. Whatever you do to one side, do to the other, so the equality stays true.

Solving 40 + 12x = 160
StepLeft sideRight side
Start40 + 12x160
Subtract 40 from both sides12x120
Divide both sides by 12x10

Check by substituting: 40 + 12 × 10 = 160. The rider went 10 km. For bills of ₹100, ₹160, ₹220 and ₹52 the distances are 5, 10, 15 and 1 km.

Running the bill backwards
501001500246810bill ₹160 → 10 kmDistance (km)Bill (₹)
See the numbers behind this picture
Running the bill backwards
Distance (km)bill = 40 + 12x
040
0.546
152
1.558
264
2.570
376
3.582
488
4.594
5100
5.5106
6112
6.5118
7124
7.5130
8136
8.5142
9148
9.5154
10160

4 · Discover

The same equation, different parameters

If the app raises its fee to ₹60, the same ₹160 buys fewer kilometres: (160 − 60) ÷ 12 = 8.33 km. The unknown is still x. The parameters changed. Keeping the roles straight, what is held fixed and what is being found, is half of reading any model.

5 · Apply

Two worked examples

Example 1, the unit check. ₹12 per km × 10 km = ₹120, and ₹120 + ₹40 = ₹160. Rupees per kilometre times kilometres gives rupees, which can be added to a fee in rupees. If the units do not line up, the equation is wrong.

Example 2, the degenerate case. Suppose the app charged 0 per km: 0 × x + 40 = 160. No x can make that true. With a rate of 0, the bill does not depend on distance, and you cannot recover distance from it.

Check yourself

The rule is bill = 50 + 15x and the bill is ₹200. What is x?

6 · Where it goes wrong

Three ways it goes wrong

7 · In Python

The bill rule in code

Here is how to implement it, step by step. The code below does exactly these steps, and every line is editable.

  1. Write the rule: bill = 40 + 12 × km.
  2. Write what you know: bill = 160.
  3. Undo the last step first: subtract 40 from both sides, giving 12 × km = 120.
  4. Undo the next step: divide both sides by 12, giving km = 10.
  5. Check by substituting: 40 + 12 × 10 = 160.
Write the rule, run it backwards
import numpy as np

fee, per_km = 40, 12                        # rupees: fixed fee, rupees per kilometre
bill = lambda km: fee + per_km * km
print("bill for 0, 5, 10 km:", [bill(k) for k in (0, 5, 10)])

# equation: 40 + 12 x = 160  ->  undo the addition, then undo the multiplication
target = 160
x = (target - fee) / per_km
print("distance that gives a bill of", target, "=", x, "km | check:", bill(x))

# the same unknown for several bills at once
bills = np.array([100, 160, 220, 52])
print("distances:", (bills - fee) / per_km)

# parameters change between experiments, x stays the unknown
for new_fee in (40, 60):
    print("fee", new_fee, "-> a 160 rupee bill covers", round((160 - new_fee) / per_km, 2), "km")
bill for 0, 5, 10 km: [40, 100, 160]
distance that gives a bill of 160 = 10.0 km | check: 160.0
distances: [ 5. 10. 15.  1.]
fee 40 -> a 160 rupee bill covers 10.0 km
fee 60 -> a 160 rupee bill covers 8.33 km
Edit and run this code in your browser

Live Python

Write the rule, run it backwards

Runs in your browser on your device. Nothing you type is sent anywhere, and nothing here changes your saved progress.

Press Ctrl+Enter (⌘+Enter on Mac) to run. Tab moves focus to the next control, as usual; use spaces to indent.

Predict, then explore

Before changing anything: A 2 km trip costs 7 rupees. If only the distance doubles, does the whole bill double? Explain which part changes before moving the distance control.

Keep coefficient a = 2 and fixed fee b = 3. Change input x from 2 to 4; compare the calculated output and table. The separate target equation asks which distance produces a bill of 11.

Try a quick prediction

1 · Start with a question

The trip gets longer. What happens to the bill?

Keep the 2-rupee/km rate and 3-rupee fee fixed. Change distance from 2 km to 4 km. The bill starts at 7 rupees; what happens next?

2 · Predict before revealing: what will the 4 km bill be?

Not scored and not saved.

Playground

Find the number that balances the bill

A book costs ₹120 and each notebook ₹35. The bill is ₹330. Instead of guessing, call the number of notebooks n: the story becomes 120 + 35n = 330. Slide n until the two sides balance.

0150300450book 1202 × 35330your side · the bill₹
Not enough: ₹140 short of the ₹330 bill.
Your side: 120 + 35n
₹190
The bill
₹330
Difference
−₹140

Solving is just undoing, in reverse order: subtract the book (330 − 120 = 210), then divide by the price (210 ÷ 35 = 6).

The general function explorer

Function Explorer

f(x) = 2x + 3. At x = 2, output = 7.

Target equation: 2x + 3 = 11. Recovered x = 4. The graph includes mathematical inputs that may be outside a real delivery's nonnegative-distance domain.

Input xOutput f(x)−44
Curves join sampled values; they are visual guides, not a proof between samples. Axes rescale for the selected rule. Use the table for exact values; a domain gap has no plotted value.
See the exact values behind the graph
Runtime function samples
Input xSelected output
-4-5
-3-3
-2-1
-11
03
0.54
15
27
39
411

In your own words: what changed, and why did the output change with it?

Now you drive

Turn the story into two functions

An equation records a story; Python can both run the story forward (bill) and undo it backward (solve).

Maths and Python, side by side
MathsPythonIn plain words
120 + 35nbook + price * nThe bill for n notebooks.
n = (330 − 120) ÷ 35(total - book) / priceUndo the addition, then the multiplication.

Live Python

bill() and solve()

Runs in your browser on your device. Nothing you type is sent anywhere, and nothing here changes your saved progress.

Quick experiments:

Press Ctrl+Enter (⌘+Enter on Mac) to run. Tab moves focus to the next control, as usual; use spaces to indent.

Stuck? Show a worked solution (try first!)
book = 120       # ₹ for the book
price = 35       # ₹ per notebook
total = 330      # the bill

def bill(n):
    return book + price * n

def solve(price, book, total):
    return (total - book) / price

n = solve(price, book, total)
print(f"{n} notebooks")
print(f"check: bill({n}) = {bill(n)}  (target {total})")

Experiment, then explain

Finish the TODOs, then try the quick experiments. Think about each question before opening its answer.

Why subtract the book before dividing?

The bill was built by multiplying first and adding second, so we undo it in reverse: remove the added ₹120, then undo the ×35. Dividing first would split the book price too.

Try a bill of ₹400. Is the answer a sensible number of notebooks?

It gives 8, which fits. Try ₹250: you get a fraction of a notebook. The equation is solved, but the story says counts must be whole numbers, so check the answer against the situation.

A balanced scale represents a ₹120 book and six ₹35 notebooks equalling ₹330.
A balanced scale represents a ₹120 book and six ₹35 notebooks equalling ₹330.
Open full-size figure for An equation turns a bill into a question (opens a new tab)↗
An equation turns a bill into a question: follow the quantities
StoryMathematical record
Book plus notebooks120 + 35n = 330
Remove the fixed price35n = 210
Divide by the price per notebookn = 6
Check against the story120 + 35 × 6 = 330

The equals sign asserts that two expressions have the same value. n is an unknown count; 35 is a rate in rupees per notebook. More complex stories can use several variables or squared terms without changing what equality means.

Relate the playground’s rule to this reading

In y = 2x + 3, x is distance in kilometres. The coefficient 2 has rupees/km units; multiplying gives a distance charge in rupees. The constant 3 is added once. y is the calculated bill, not an observed purchase.

To use a known bill, write 11 = 2x + 3. Subtract 3 from both sides to preserve equality, then divide both sides by 2: x = 4 km. Substitution checks the answer: 2 × 4 + 3 = 11.

Representing a relationship and solving a particular question are different steps. An equation can have one solution, several, or none under its constraints. It also leaves out real-world details unless we explicitly model them.

The explorer writes the same family as f(x) = ax + b. f(x) names the output, a the coefficient and b the fixed fee; f(x) does not mean f multiplied by x.

Symbol and unit reference
x
Variable: distance in kilometres
a
Coefficient, rupees per kilometre
b
Constant fee, rupees
t, =
Target bill and equality
Separate practice example: a different pricing rule

For 3x + 1 = 13: subtract 1 from both sides to get 3x = 12; divide both sides by 3 to get x = 4. Substitute back: 3 × 4 + 1 = 13. If a = 0, 0x + b = t has every input as a solution when b = t, and none otherwise.

Connect the relationship to Python

distance_km = 4
price_per_km = 2
fixed_fee = 3
bill = price_per_km * distance_km + fixed_fee
print(bill)  # 11 rupees

The names preserve units and roles. * multiplies the rate and distance; + adds the fee. Python = assigns a value; mathematical = asserts equality.

Why this matters for ML

A prediction model also uses adjustable coefficients. Solving this tiny equation helps explain a prediction without assuming a trained model is correct.

Try a different situation

A bike rental costs 4 rupees per hour plus a 5-rupee fee. Without listing every possible rental, explain how to represent its cost and what one extra hour changes.

Compare your reasoning

Let h be hours and C the cost: C = 4h + 5. One extra hour adds 4 rupees; the 5-rupee fee stays fixed. At 2 hours C = 13 and at 3 hours C = 17.

Not scored or saved. Compare your reasoning, not just the answer.

Read a larger expression when you’re ready

The five-level Equation X-Ray connects these ideas to multiple inputs, curves, nested functions and indexed sums. Choose any level; advanced solving is not required.

Equation X-Ray · Read the structure, then explain it

Mathematics as a language

Start with a familiar rule and build toward a larger expression. Reading its pieces comes before solving advanced equations. You can explore any level.

One rule, many possibilities

A trip has a 3-rupee booking fee and costs 2 rupees per kilometre. How can one statement describe any permitted distance?

y = 2x + 3

Read the relationship before trying to solve it. This is an illustrative example, separate from the live experiment.

Choose a building block to inspect its role.

Read the operations: Multiply distance by its rate, then add the fee. If a bill is known, solving asks which distance makes both sides equal.

Build the expression from smaller operations

Choose a valid construction in the stated order. This exercise organizes dependencies; it does not claim every implementation must evaluate independent branches in this order.

    What problem could this relationship represent?

    A booking fee plus a distance charge is one possible interpretation; a fixed production setup cost plus a per-item charge has the same structure.

    Context we still need: Symbols alone do not establish currency, physical meaning or whether negative distances are allowed.

    Connect the operations to code
    bill = 2 * distance_km + 3

    Read the code as a map of operations. It is not executed here; imports, shapes and numerical safeguards depend on the actual lesson.

    Explain a changed situation

    Your notes and reveals are temporary. This reading practice does not change lesson completion or saved assessment evidence.

    Understanding checks

    Use the worked reasoning above. Answers within 0.001 count as correct.

    1. A charge is (2 rupees/km) × x km + 3 rupees. What are the roles?
    2. Evaluate the expression 2x + 3 at x = 4.
    3. A bill satisfies 3x + 1 = 13. What is x?
    4. Which first step preserves 3x + 1 = 13?

    Carry this idea forward

    An equation compresses a relationship; solving selects values that satisfy a question and its constraints.

    Next, ask which inputs a rule accepts and whether each gets one well-defined output.

    What the existing checks cover
    • Distinguish a variable, coefficient and constant in a practical rule.
    • Evaluate an expression with correct operation order and units.
    • Solve and verify a simple linear equation.
    • Explain why an equation operation must preserve equality.

    Build your lesson evidence

    Try the experiment. 0 of 4 checks done.