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.
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.
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 |
|---|---|---|
| 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 |
|
| 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 |
|
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".
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 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 |
|
| 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 |
|
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".
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 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 |
|
| 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 |
|
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".
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 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 |
|
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".
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.