Advanced ยท 46 projects ยท premium, free for now ยท ages 13+
Coding Grandmaster from scratch.
Coding Grandmaster is for learners who know Python basics and want to understand how the clever parts work. Instead of importing libraries, you build them: a sieve, a sorting counter, Bayes' rule, a regression line, a nearest-neighbour classifier and a small neural network, one short project at a time.
46 lessons
What you will do
1. Algorithms and speed
How fast is it? Counting steps
Write pair_checks(n): two nested loops that count every pair (i, j) with i smaller than j among n items, and return the count. The program prints pair_checks(10).
Start โ2Searching one by one
Write find(items, target) that returns a pair (index, comparisons). If the target is missing, the index is -1 and the comparisons equal the length of the list.
Start โ3Halving the search
Write binary_search(items, target) for a sorted list. Return (index, steps) where steps counts how many middle items you looked at, or (-1, steps) if it is missing.
Start โ4Two ways to sort
Write bubble_sort(items) and selection_sort(items). Each returns (sorted_list, swaps) and must not change the list it was given. The program prints both results for the list.
Start โ5The growth race
For each size in the list print one line like n=10 linear=10 nlogn=33 quadratic=100, where nlogn is int(n * math.log2(n)).
Start โ6Remembering answers
Write fib_naive(n) returning (value, calls) and fib_memo(n, memo) returning the value while counting calls in memo["calls"]. Print the results for 20.
Start โ2. Number magic
Euclid's shortcut
Write gcd_steps(a, b) returning (gcd, steps) where steps counts the remainder steps, and lcm(a, b). Print gcd_steps(48, 18) and lcm(4, 6).
Start โ8The sieve of Eratosthenes
Write primes_below(n) using a list of True/False flags (a sieve) that returns the list of primes less than n. Print how many primes there are below 100 and the last one.
Start โ9Digits and casting out nines
Write digit_sum(n) using % and //, and digital_root(n) that repeats digit_sum until one digit remains. Print both for 98765.
Start โ10Powers in a flash
Write power_steps(base, exp) that returns (result, multiplications) using repeated squaring, and pow_mod(base, exp, m) that returns base ** exp % m the same way (without ever building the full power).
Start โ11Perfect numbers
Write divisor_sum(n) (the sum of proper divisors, found by looping d up to the square root and adding both d and n // d) and print the perfect numbers below 1000.
Start โ12Counting in other bases
Write to_base(n, base) returning the digits as text, using the string "0123456789ABCDEF". Print 10 in binary and 255 in hexadecimal.
Start โ3. Bit play
Seeing the bits
Print each of 5, 12 and 255 as 8 binary digits, and write count_ones(n) that counts the 1 bits using & and >>.
Start โ14One-line bit tricks
Write is_power_of_two(n) using n & (n - 1), is_odd(n) using n & 1, and print the powers of two up to 200 using a list comprehension.
Start โ15XOR magic
Swap a and b with three XOR lines (no temporary variable), and write lonely(numbers) that returns the number that appears only once by XOR-ing everything together.
Start โ16Set, clear and toggle
Write set_bit(n, i), clear_bit(n, i), toggle_bit(n, i) and test_bit(n, i) (True or False) using shifts and bitwise operators.
Start โ17Every subset
Write subsets(items) returning a list of every subset as a list, in the order of the counter 0 to 2^n โ 1, using bit tests. Print how many subsets four items have, and the subsets of two items.
Start โ18Permission flags
With READ = 4, WRITE = 2 and EXEC = 1, write grant(perms, flag), revoke(perms, flag), has(perms, flag) and describe(perms) which returns text like r-x (r, w and x, or - for a missing one).
Start โ4. Probability
Counting outcomes
Write ways(target), the number of dice pairs that add up to target, and as_fraction(top, bottom) that returns text like 1/6 in lowest terms. Print the chance of a total of 7.
Start โ20The OR rule
Build the 52-card deck as (rank, suit) pairs, then count the cards that are the chosen suit, the chosen rank, both, and either. Print the four counts and the chance of either as a fraction in lowest terms.
Start โ21Given thatโฆ
For the chosen club print how many students are in it, how many passed, and P(passed | club) as a percentage with one decimal place. Then print P(passed) for all students.
Start โ22Bayes and the medical test
Write posterior(prior, sensitivity, specificity) returning P(sick | positive) rounded to 4 decimal places. Print it for prior 0.01, sensitivity 0.9, specificity 0.9.
Start โ23The binomial distribution
Write binomial(n, k, p) and use it to print the chance of exactly 3 heads in 5 fair flips, the chance of at least 4 heads, and the total of all the chances (rounded to 6 places).
Start โ24How computers fake randomness
Write next_value(seed) with that formula, and roll(seed) = 1 + seed % 6. Starting from the given seed, roll 600 times (feeding each result back in) and print how many times each face 1 to 6 came up.
Start โ5. Statistics
Averages
Write mean(data), median(data) and mode(data). If several values tie for most common, mode returns the smallest of them. Print all three for the list.
Start โ26How spread out?
Write data_range(data), variance(data) and std_dev(data) (population versions, dividing by n). Print them for the data, rounding the standard deviation to 4 decimal places.
Start โ27Quartiles and outliers
Write quartiles(data) returning (q1, q2, q3) by the method above, and outliers(data) returning the sorted list of outliers by the 1.5 ร IQR rule.
Start โ28A histogram in text
Count how many students got each grade and print one line per grade in alphabetical order, like A | #### 4.
Start โ29Do two things move together?
Write correlation(xs, ys) that returns Pearson's r rounded to 4 decimal places. Print it for study hours against marks.
Start โ30Scaling and z-scores
Write min_max(values) and z_scores(values) (use the population standard deviation). Both return lists with each number rounded to 2 decimal places.
Start โ6. Data science from scratch
Records, filters and rankings
Keep the students whose score is at least cutoff, sort them by highest score (ties by name), print how many qualified, and print the first top of them as a numbered list.
Start โ32Group by: totals per region
For every sale of at least minimum, add it to its region. Print one line per region (alphabetical) like east: total 360, average 180.0, orders 2.
Start โ33Cleaning messy data
Write fill_missing(values) that replaces each None with the mean of the other values rounded to 1 decimal place, and remove_duplicates(values) that keeps only the first of each repeated value in order. Print both results for the readings.
Start โ34Draw a bar chart
Draw one filled bar for each value, 40 wide and 15 times the value tall, 50 apart, starting at x = -150 along the line y = -100, using a different colour from the list for each.
Start โ35Draw a line chart
Draw an x axis and a y axis from the origin at (-150, -100), then plot the sales as dots (50 apart across, 5 times the value up) joined by lines.
Start โ36Capstone: a report table
Write grade(score) (A for 80 or more, B for 70 or more, otherwise C) and print the ranking, highest first, as an aligned table with a header, then the average (2 decimal places) and the name of the top scorer.
Start โ7. Machine learning from scratch
Predictions and error
Write predict(x, m, b) and mse(xs, ys, m, b). Print the prediction for each size and the mean squared error of the line with the given m and b, rounded to 2 decimal places.
Start โ38Training by searching
Try every m from 0 to 100 in steps of 5 and every b from 0 to 200 in steps of 10 with the same data. Print the best m, the best b and their error rounded to 2 decimal places.
Start โ39Gradient descent
Starting from m = 0, repeat steps times: compute the gradient, then do m = m - lr * gradient. Print the final m rounded to 4 decimal places and the final mean squared error rounded to 4.
Start โ40The straight-line formula
Compute the slope and intercept with these formulas, print them rounded to 3 decimal places, and print the prediction for new_x rounded to 2 places.
Start โ41Classifying by neighbours
Write classify(point, train, k): sort the training examples by distance to the point, take the k closest, and return the label that appears most among them (if tied, the label of the nearest one).
Start โ42A perceptron learns AND
Train a perceptron on the AND truth table starting from zero weights, for the number of epochs, with each update using a learning rate of 1. Print the final weights and bias as w1 w2 b, then the four predictions.
Start โ8. Neural networks from scratch
A single neuron
Write sigmoid(z) and neuron(inputs, weights, bias) which returns the sigmoid of the weighted sum plus the bias. Print the neuron's output, rounded to 4 decimal places, for each input pair.
Start โ44A two-layer network
Write forward(x1, x2) for a network with two hidden neurons and one output neuron, using the given weights, and print the output rounded to 3 decimal places for the four input pairs.
Start โ45Teaching a neuron OR
Train a neuron on the OR table, starting from weights 0.1, -0.1 and bias 0, for 1,000 epochs with learning rate lr. Print the four outputs rounded to 2 decimal places.
Start โ46Why XOR needs a hidden layer
Write step(z) and xor_net(a, b) using two hidden neurons, h1 = step(a + b - 0.5) and h2 = step(a + b - 1.5), and the output step(h1 - h2 - 0.5). Print the XOR table, one line per row, like 0 1 -> 1.
Start โNext
Keep going
Learn HTML
HTML is the language that builds every web page. Type a little code, watch the page appear next to it, and get a tick when you have it right.
8 lessons ยท Beginner ยท ages 9+ โLearn CSS
CSS makes a web page look good. The page is already written; you write the style rules and watch it change as you type.
8 lessons ยท Beginner ยท ages 10+ โLearn JavaScript
JavaScript makes pages do things. Write a few lines, press Run, and see what your program prints. The lessons start from nothing.
8 lessons ยท Beginner ยท ages 11+ โLearn Python
Python is one of the friendliest languages to start with. Each lesson explains one idea in a minute, then gives you one small task: write the code, press Run, and get a tick when it is right.
24 lessons ยท Beginner ยท ages 9+ โPython Studio
Premium ยท free for nowPython Studio is for learners who have started Python and want to make things: draw spirals and rosettes with the turtle, write secret codes, referee a game, build a deck of cards and make a ball bounce. Each project has one clear goal and instant checking.
18 lessons ยท Beginner to confident ยท ages 10+ โWeb Developer Path
A complete start to web development. Each lesson explains one idea, shows a colourful example you can run, and gives you code to type and practise, with a live preview and instant checking as you go.
18 lessons ยท Beginner to intermediate ยท ages 12+ โFAQ
Coding Grandmaster: questions
What will I learn in Coding Grandmaster?
You will build algorithms, probability and statistics tools, a data report with charts, and machine-learning models from scratch in Python, understanding each step. Each of the 46 lessons has one small task and automatic checking.
How long does it take?
About 690 minutes in total, 46 short lessons of around 15 minutes each. Go at your own pace.
Do I need to know anything first?
Yes: you should be comfortable with Python basics, meaning variables, loops, lists and functions. The free Learn Python course covers exactly that.
Do I get a certificate?
Yes. Finish all the lessons and you can download a free certificate of completion with your name. It is a record of what you did, not an accredited qualification.
Start a conversation
Want a teacher beside you?
Tell us the learner's age, country and goal. We suggest a starting point and confirm the format and price before anything is booked.
- Tell us the learnerโs age or grade and goals
- Weโll suggest a suitable class or learning path
- Weโll confirm format, timing and fees with a parent or guardian
Play it, don't just read it
Write some code right now
Free games that need no sign-up. Pick one and play for five minutes.
Pick a game
- Bug HunterA Python program prints the wrong answer. Find the one line with theโฆPlay
- Predict the OutputRead a short Python program and choose what it prints. Then watch it runโฆPlay
- Code BuilderThe lines of a Python program are mixed up. Tap them into the rightโฆPlay
- Code JungleWrite real Python to guide Miko the monkey to every banana. 24 levels:โฆPlay