Source: https://mokxi.com/teachers/plans/python-for-science
Updated: 2026-11-19

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.

Start a class from this course

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.

Lesson | Time | What students do

Units Numbers 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

- Run it: weight on Mars
- The unit bug that lost a spacecraft
- How far is Mars, in seconds?
- Big numbers: scientific notation
- The float that is not 0.3
- A converter that cannot mix units up

Numeric methods How 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

- Run it: a square root from scratch
- Stop when it stops changing
- Bisection: a method that cannot fail
- Where is Mars? Kepler's equation
- 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.

Lesson | Time | What students do

A falling ball Simulate 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

- Run it: Euler steps
- Drop it on Mars
- A smaller step
- Add air: what the formula cannot do
- Into orbit with Euler
- The one-swap fix: Euler-Cromer

Monte Carlo Answer 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

- Run it: pi from darts
- How fast does it get better?
- Will the lander hit a boulder?
- 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.

Lesson | Time | What students do

Statistics of a sensor Turn 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

- Run it: ten timings
- Spread: the standard deviation
- How sure is the mean? Standard error
- Check against the library
- Now let a sensor time it

Fitting a line Find 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

- Run it: straighten the curve
- Least squares, by hand
- Read g off the slope
- Is it really a line? Residuals and R^2
- 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.

Lesson | Time | What students do

Project: measure g with a pendulum The 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

- Run it: the photogate rig
- From times to g
- Take it to Mars
- An honest error bar
- Which world is this?
- 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.

Start a class from this course See the demo class

More units

## Other lesson plans

Electronics basics 20 lessons, about 10 h. Embedded on the Arduino Uno 16 lessons, about 12 h. Embedded on the ESP32-C3 13 lessons, about 11 h. Embedded on the Raspberry Pi Pico 7 lessons, about 6 h. Build your own fight stick 5 lessons, about 4 h. Embedded on the STM32F411 6 lessons, about 6 h. C++ on a board 13 lessons, about 10 h. Digital logic and memory 4 lessons, about 4 h. Interactive devices on the Uno 9 lessons, about 8 h. From gates to a computer 23 lessons, about 16 h. Build a claw machine 8 lessons, about 6 h. Every unit All the courses as ready-made units, on the teachers page.
