44 concepts · 9 lessons

Python concepts, each with a project

Looking for one thing rather than a course? Each idea below is used in a short script that builds a pattern, and the lesson explains it line by line.

  1. Lesson 1 · Beginner Arrays and angles with the golden angle
    • numpy arrays with np.arange
    • arithmetic on a whole array at once
    • radians, np.cos and np.sin
    • from an angle and a distance to x and y
    • a scatter plot coloured by a value
  2. Lesson 2 · Beginner Loops and remainders with the times table on a circle
    • a for loop over pairs with zip
    • the remainder % and angles that wrap around
    • a line from two points with plt.plot
    • exploring by changing one parameter
  3. Lesson 3 · Beginner Randomness and counting with the galton board
    • random numbers with np.random.default_rng
    • True and False counted as 1 and 0
    • counting with np.bincount
    • a list comprehension
    • a simulation checked against a formula
  4. Lesson 4 · Intermediate Loops that remember with the chaos game
    • a loop that carries its state from step to step
    • random whole numbers with rng.integers
    • a while loop for a condition
    • arrays of points and slicing
    • np.column_stack
  5. Lesson 5 · Intermediate Formulas on arrays with the pendulum wave
    • a physics formula applied to a whole array
    • np.round and print for a quick check
    • several plots side by side with plt.subplots
    • f-strings
    • phase: where in its swing a pendulum is
  6. Lesson 6 · Intermediate Functions and recursion with the sorting race
    • functions, and passing a function as a value
    • recursion: a function that calls itself on smaller parts
    • a counter kept in a dictionary
    • assert to check a result
    • how work grows: n² against n·log n
  7. Lesson 7 · Intermediate Stepping through time with the ball in a spinning ring
    • a simulation: small time steps in a while loop
    • vectors as numpy arrays
    • the dot product and a reflection
    • angles with np.arctan2, wrapped round
    • break to leave a loop
  8. Lesson 8 · Advanced Forces and integration with the three-body orbits
    • Newton’s gravity as vectors
    • nested loops over pairs of bodies
    • the leapfrog method of integration
    • a 3-D array: step × body × coordinate
    • checking a simulation by what must not change
  9. Lesson 9 · Advanced Grids and diffusion with the turing patterns
    • 2-D arrays as a grid of cells
    • np.roll for neighbours, with edges that wrap around
    • the Laplacian: a cell against its neighbours
    • updating a whole grid in one line
    • showing an array with plt.imshow