Lesson plan

Python for science and math lesson plan

Space science in plain Python on a Raspberry Pi: units, numeric methods, Euler steps from a falling ball to an orbit, Monte Carlo, the statistics of a sensor, least squares, and a photogate pendulum that measures g.

4 chapters, 7 lessons, about 5 hours, on the Raspberry Pi 4 Model B. Every lesson runs in the browser, with nothing to install.

The unit

Objectives and materials

By the end, students can

  • Units that crashed a probe, floats that are not exact, and methods that solve equations by guessing well.
  • Step time forward to drop a ball and fly an orbit, and throw random darts to answer what formulas cannot.
  • Mean, spread and error bars, a sensor against a stopwatch, and the best line through the data.
  • Build a photogate pendulum and measure gravity, on Earth and on Mars, with an honest error bar.

Materials for the whole unit

  • Half breadboard
  • LED x 2
  • Photo interrupter, slot
  • Raspberry Pi 4 Model B
  • Resistor x 2

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 1 h 30 min

Numbers that mean something

Units that crashed a probe, floats that are not exact, and methods that solve equations by guessing well.

LessonTimeWhat students do
UnitsNumbers in science carry units: weigh an astronaut on Mars, redo the arithmetic that lost the Mars Climate Orbiter, time a radio signal across the solar system, write huge numbers in scientific notation, and meet the float that is not quite 0.3.50 min
  1. Run it: weight on Mars
  2. The unit bug that lost a spacecraft
  3. How far is Mars, in seconds?
  4. Big numbers: scientific notation
  5. The float that is not 0.3
  6. A converter that cannot mix units up
Numeric methodsHow computers actually solve math: Newton's method for square roots, a stopping rule, bisection for any equation, Kepler's equation for where Mars is in its orbit, and the trapezoid rule for areas, with the error measured each time.40 min
  1. Run it: a square root from scratch
  2. Stop when it stops changing
  3. Bisection: a method that cannot fail
  4. Where is Mars? Kepler's equation
  5. Areas: the trapezoid rule

Materials

  • Half breadboard
  • LED x 2
  • Raspberry Pi 4 Model B
  • Resistor x 2

Check for understanding

Each student finishes "Numeric methods" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Areas: the trapezoid rule".

Chapter 2. About 1 h 20 min

Simulate it

Step time forward to drop a ball and fly an orbit, and throw random darts to answer what formulas cannot.

LessonTimeWhat students do
A falling ballSimulate motion the way physics engines do, one small time step at a time: a ball dropped on Earth and on Mars, the cost of a big step, air drag that no formula solves neatly, and an orbit around Earth that drifts until one swapped pair of lines fixes it.50 min
  1. Run it: Euler steps
  2. Drop it on Mars
  3. A smaller step
  4. Add air: what the formula cannot do
  5. Into orbit with Euler
  6. The one-swap fix: Euler-Cromer
Monte CarloAnswer hard questions with random numbers: estimate pi from darts, measure how the error shrinks with more samples, find a Mars lander's chance of hitting a boulder, and use seeds so a random experiment can be repeated exactly.30 min
  1. Run it: pi from darts
  2. How fast does it get better?
  3. Will the lander hit a boulder?
  4. Seeds: random, but repeatable

Materials

  • Half breadboard
  • LED x 2
  • Raspberry Pi 4 Model B
  • Resistor x 2

Check for understanding

Each student finishes "Monte Carlo" on their own, without opening the hints. The simulator checks 4 of its 4 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Seeds: random, but repeatable".

Chapter 3. About 1 h 20 min

Measure it

Mean, spread and error bars, a sensor against a stopwatch, and the best line through the data.

LessonTimeWhat students do
Statistics of a sensorTurn a pile of measurements into a result: mean, standard deviation by hand, the standard error that shrinks with more data, the statistics module as a check, and then a photogate on the Pi that measures the same swing far better than a thumb on a stopwatch.40 min
  1. Run it: ten timings
  2. Spread: the standard deviation
  3. How sure is the mean? Standard error
  4. Check against the library
  5. Now let a sensor time it
Fitting a lineFind the law in the data: straighten a pendulum's curve by plotting T^2 against length, fit the best line by least squares written by hand, read g from its slope, judge the fit with residuals and R^2, and use it to predict.40 min
  1. Run it: straighten the curve
  2. Least squares, by hand
  3. Read g off the slope
  4. Is it really a line? Residuals and R^2
  5. Predict: the seconds pendulum

Materials

  • Half breadboard
  • LED x 2
  • Photo interrupter, slot
  • Raspberry Pi 4 Model B
  • Resistor x 2

Check for understanding

Each student finishes "Fitting a line" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Predict: the seconds pendulum".

Chapter 4. About 50 min

Project

Build a photogate pendulum and measure gravity, on Earth and on Mars, with an honest error bar.

LessonTimeWhat students do
Project: measure g with a pendulumThe finale: time a pendulum with a photogate on GPIO17, turn the times into g, take the experiment to Mars, put an honest error bar on the result, and write a program that works out which world the pendulum is swinging on.50 min
  1. Run it: the photogate rig
  2. From times to g
  3. Take it to Mars
  4. An honest error bar
  5. Which world is this?
  6. Your lab report

Materials

  • Photo interrupter, slot
  • Raspberry Pi 4 Model B

Check for understanding

Each student finishes "Project: measure g with a pendulum" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Your lab report".

Your class

Teach this unit as a class

Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.