Interactive, runnable Python. Edit the code, run it in your browser, no setup required.
You will write a function for the differences of a list, use it to test for an AP, and sort some lists. The idea. A list is an AP when all the differences between neighbouring terms are equal. A list of one or two num…
You will write the formula for the nth term, a function that finds which term a number is, and use them to count. The idea. a_n = a + (n - 1)d. To find which term a number v is, n = (v - a)/(d) + 1, and it must be a w…
You will write the terms of an arithmetic progression and its sum by the formula, then check that the two agree. Your tasks. In ap_terms, return the list of the first n terms. In ap_sum, return the sum of the first n…
You will find how many terms an arithmetic progression needs to reach a target, and recover the terms from a formula for the sum. Your tasks. In terms_to_reach, return the smallest n for which the sum of the first n t…
You will write a function for the left side of a quadratic equation, use it to test roots, and pick the roots out of a list. The idea. A number is a root of ax^2 + bx + c = 0 when the left side is 0 there. A computer…
You will write a function that finds the split of the middle term, use it to get the roots, and solve a problem about a photograph. The idea. For ax^2 + bx + c you need p and q with p + q = b and p × q = a × c. Then a…
You will write the quadratic formula as a Python function and use it. Your tasks. In discriminant, return b^2 - 4ac. In roots, return the list of real roots, the one with + first. Return an empty list when the discrim…
The discriminant sorts quadratic equations into three kinds without solving them. You will write the sorter and use it. Your tasks. In nature, return "two distinct", "equal" or "none", from D = b^2 - 4ac. Set none_cou…
A formula is an identity when it holds at every angle. The computer can test five hundred pairs of angles in a moment. You will write the formula for (x + y), find its largest error, and count how often the false rule…
Archimedes found π by drawing polygons inside a circle and doubling the number of sides again and again. A regular polygon with n sides inside a circle of radius 1 has half-perimeter n(π)/(n), which comes closer and c…
Write three small functions that a calculator would need: one takes away whole turns, one finds the quadrant, and one lists the functions that are positive. The idea. x % (2 * math.pi) takes away whole turns. Dividing…
A wave is y = a(bx + c) + d with a = -2.5, b = 3, c = 1.2 and d = 4. Find its amplitude, its period, its highest and lowest values, and the first x > 0 where it is highest. The program then draws it, so you can see yo…
You will write two small functions that change the unit of an angle, and use one of them to write angles as multiples of π. The idea. π rad = 180^°. So multiply by (π)/(180) for radians, and by (180)/(π) for degrees.…
A cart has wheels of radius 0.3 m, which turn 180 times each minute. You will find how far it goes in one turn, its angular speed, its speed, and the turns and the time for a trip of 1500 m. The idea. One turn moves t…
For a prime d, if d divides a^2 then d divides a. For other numbers it can fail. You will find every divisor d from 2 to 20 that fails, and look at what they have in common. The idea. For one d, try a = 1, 2, 3, and l…
No fraction has a square of exactly 2. But some come very close. For each bottom q, take the top p nearest to q√(2), and measure the miss p^2 - 2q^2. You will find the bottoms up to 1000 where the miss is only 1 or -1…
You will write a function that breaks a number into primes, then use it to test for primes and to find numbers in which no prime repeats. The idea. Divide by 2 while you can, then by 3, then by 4 (which never divides,…
You will write Euclid's division method as a function, build the LCM from it, and use both on a timetable. The idea. While b is not 0, replace the pair (a, b) by (b, r), where r is the remainder of a divided by b. Whe…
Least squares picks the straight line that makes the squared errors smallest. For a line it has a short formula, which you will write and use on six noisy readings. The idea. m = Σ (x - x)(y - y)Σ (x - x)^2 and c = y…
In Python a function is a value, so you can build f ° g as a new function. You will compose two machines and find where the order does not matter. The idea. compose(f, g) returns a new function that does g first and t…
An inverse undoes a function, and its graph is the mirror image in y = x. You will write an inverse, test the round trip, and check that mirrored points land on the inverse. The idea. For f(x) = 3x - 2, solving y = 3x…
Moving y = x^2 gives y = a(x - h)^2 + k. You will find a vertex from the standard form, turn the vertex form back into the standard form, and find the zeros. The idea. The vertex of ax^2 + bx + c is at x = -(b)/(2a).…
The modulus, the signum, the greatest integer and the fractional part are all short rules. You will write three of them without the math module, and test them on tricky inputs. The idea. int(x) cuts off the decimals,…
Every change to a graph moves each point in a simple way. You will write the moves for a shift, a stretch and the two flips, and follow one point through them. The idea. On y = f(x - h) + k the point (p, q) goes to (p…
A relation is a list of pairs. It is a function on a domain when every element of the domain appears exactly once as a first entry. You will test that and read off images. The idea. Count how often each element of the…