TExcelTAD
Home › Basic Math & Pre-Algebra › Basic Math Intro

Basic Math Intro

This course rebuilds the math you met in primary and middle school, from whole numbers to logarithms and first statistics, and checks every idea with a few lines of Python you can run right on the page. It is written for people who are (or want to become) programmers, so each topic also shows where software uses it.

Why a programmer needs basic math

Code is full of small arithmetic decisions. How many pages do 95 search results fill at 10 per page? Which tile of a game map is the player standing on? Why does 0.1 + 0.2 not print 0.3? How fast does a binary search finish? Each of these questions is answered by a topic in this course: division with remainders, place value, floating point and logarithms.

You do not need to remember anything from school. Every lesson starts from the beginning, uses plain language and small numbers, and then lets the computer do the heavy lifting.

What is in the course

The chapter order follows Debra Anne Ross's book Master Math: Basic Math and Pre-Algebra, which serves as the reference for the order of topics; all explanations, examples and exercises here are our own.

Section What you learn
Getting Started this page and Math with Python
Numbers and Their Operations kinds of numbers, the number line, place value, the four operations, signed numbers, order of operations, factors, primes, GCF and LCM
Fractions what a fraction is, simplifying, mixed numbers, all four operations
Decimals decimal place value, calculating with decimals, rounding and repeating decimals
Percentages percent of a number, percent change, simple and compound interest
Converting moving between fractions, decimals and percents
Ratios, Proportions and Variation rates, proportions, direct and inverse variation, units
Powers and Exponents exponent laws, negative exponents, scientific notation, powers of two
Logarithms what a log is, log laws, common and natural logs, log scales
Roots and Radicals square roots, simplifying radicals, nth roots, the Pythagorean theorem
Important Statistical Quantities mean, median, mode, spread, weighted averages, first probability
Toward Algebra variables, equations, inequalities, the coordinate plane
Math in Computing binary and hex, overflow, floating point, modular arithmetic, Big-O
Practice exercises and a mini project

The first ten numbered sections mirror the book's chapters. "Toward Algebra" and "Math in Computing" are extras that bridge to the next courses and to everyday programming.

How the playground works

Every grey box marked ▶ Run is a real Python program. Press the button and it runs in your browser (Python 3.13 compiled to WebAssembly), with no installation and nothing sent to a server. You can edit the code and run it again as often as you like. The box below the code shows what the program prints.

python · try it yourself
apples = 7
friends = 3

print("Each friend gets", apples // friends, "apples")
print("Apples left over:", apples % friends)
print("Exact share:", apples / friends)
Each friend gets 2 apples
Apples left over: 1
Exact share: 2.3333333333333335

Three lines of code already show three different ideas: whole-number division, the remainder, and an ordinary decimal answer (with a tiny rounding wobble in the last digit, which the Floating Point lesson explains). The next lesson, Math with Python, teaches the handful of Python operators you need. No earlier programming experience is required.

Tip: Change the numbers in an example before you read the explanation. Guess the output first, then run it. Being surprised by a result is the fastest way to learn.

Each lesson ends with a short Test yourself quiz. Click an answer to see whether it is right and why.

The Mathematics track

This course is the first step of the Mathematics track. Only this course and Calculus Essentials exist today; the others are planned (see the roadmap), and their links open a "coming soon" page until they are written.

Your goal Suggested path
School math up to university Basic Math → Algebra → Pre-Calculus → Calculus Essentials → Calculus in Depth → Linear Algebra → Differential Equations
Game developer Basic Math → Calculus Essentials (functions, derivatives, vectors and motion, differential equations) → Linear Algebra → Math for Games and Game Physics
AI / ML engineer Calculus Essentials → Linear Algebra → Probability → Math for ML → Optimization → Machine Learning
Deep learning and LLMs Calculus Essentials (partial derivatives, backpropagation) → Linear Algebra → Math for Deep Learning → Information Theory → Generative AI & LLMs
Algorithms and interviews Basic Math (especially logarithms and growth rates) → Discrete Math → Data Structures & Algorithms
Security Basic Math (especially primes and modular arithmetic) → Number Theory & Cryptography → Cybersecurity

Whatever your goal, Basic Math is the shared foundation. If most of it feels familiar, skim the lessons, do the quizzes, and jump to the sections you are unsure about.

A first taste

Here is a question you will be able to answer fully by the end of the Primes lesson: which numbers up to 30 have no divisors except 1 and themselves?

python · try it yourself
primes = []
for n in range(2, 31):
    if all(n % d != 0 for d in range(2, n)):
        primes.append(n)

print(primes)
print("How many:", len(primes))
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
How many: 10

Don't worry if the code looks strange now. By the end of the first section you will be able to read every line of it.

Exercises

Exercise 1: Pages of results

A search returns 95 results and shows 10 per page. How many pages are needed, and how many results are on the last page?

Answer

10 pages; the last page holds 5 results.

Solution
95÷10=9 remainder 59 full pages hold 90 results, and the 5 left over need one more page.pages=9+1=10, last page=5 results\begin{aligned} &95 \div 10 = 9 \text{ remainder } 5 \\ &\text{9 full pages hold 90 results, and the 5 left over need one more page.} \\ &\text{pages} = 9 + 1 = 10,\ \text{last page} = 5 \text{ results} \end{aligned}

Exercise 2: Share the sweets

Change the apples example so that 23 sweets are shared between 4 children. Before running it, predict the three printed numbers.

Answer

Each child gets 5, 3 are left over, and the exact share is 5.75.

Solution

4×5=204 \times 5 = 20, so each child gets 5 and 23−20=323 - 20 = 3 are left. The exact share is 23÷4=534=5.7523 \div 4 = 5\tfrac{3}{4} = 5.75.

python · try it yourself
sweets = 23
children = 4

print("Each child gets", sweets // children, "sweets")
print("Sweets left over:", sweets % children)
print("Exact share:", sweets / children)
Each child gets 5 sweets
Sweets left over: 3
Exact share: 5.75

Exercise 3: More primes

Edit the "first taste" program so it lists the primes up to 50 instead of 30. How many are there?

Answer

15 primes: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47.

Solution

Only the end of the range changes. range(2, 51) stops before 51, so it includes 50.

python · try it yourself
primes = []
for n in range(2, 51):
    if all(n % d != 0 for d in range(2, n)):
        primes.append(n)

print(primes)
print("How many:", len(primes))
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
How many: 15

Test yourself

What happens when you press ▶ Run on an example in this course?

  1. The code is sent to a teacher for grading
  2. The Python code runs in your own browser and its printed output appears below
  3. Nothing, the examples are pictures
  4. You must install Python first

The order of the course's main chapters follows which reference?

  1. A random order
  2. The W3Schools Python tutorial
  3. Debra Anne Ross's Master Math: Basic Math and Pre-Algebra
  4. The order of the calculus course

In the apples example, 7 // 3 printed 2 and 7 % 3 printed 1. What does the 1 mean?

  1. The apples left over after sharing equally
  2. One apple per friend
  3. An error code
  4. The exact answer rounded down