The page has five stations, and each one introduces exactly one library at the moment it becomes useful: physical constants, then arrays and plots, then symbolic math.
1. Python as a scientific calculator¶
Our first import: scipy.constants knows every physical constant, so you never mistype one (full list). One line of code, and , , , , are all at your fingertips:
A green laser pointer emits 532 nm light. What is the energy of one of its photons? Type the formula almost exactly as you would write it:
Joules are inconvenient at the atomic scale, so chemists quote photon energies in electron volts (divide by the electron charge) or kJ/mol (multiply by Avogadro’s number). Unit conversion is just arithmetic:
A mole of green photons carries about 225 kJ, and a typical C-C single bond costs 347 kJ/mol. Can light break a bond? Drag the slider and find out. Making an interactive control is one line of code:
Notice the chemistry hiding in this toy: visible light cannot touch a C-C bond, but ultraviolet light below roughly 345 nm can. That is why UV radiation damages molecules and sunscreen exists.
2. The de Broglie wavelength, in three lines¶
The same calculator settles a chapter question: why do electrons diffract but baseballs do not? Compute for both. For the electron we use its speed in the ground state of the Bohr model Bohr, 1913, m/s:
3. Functions: the hydrogen spectrum¶
When a formula gets used more than once, wrap it in a function. The Rydberg formula predicts every line hydrogen emits when an electron falls from level to :
Now the function powers a live energy-level diagram. Pick a series and an upper level; the diagram draws the transition and colors the emitted photon:
Gray arrows mean the photon lies outside the visible window. Only the Balmer series lands in it, which is why hydrogen discharge tubes glow red-pink: you are looking mostly at the 656 nm line you computed above.
4. Plotting: blackbody radiation¶
Two more imports, and they are the workhorses of all scientific Python: numpy handles arrays of numbers, and matplotlib turns them into figures.
Planck’s law Planck, 1901 started quantum mechanics. Typed as code, it is three lines:
The default 5800 K is the surface of the Sun: its peak sits right in the visible band (evolution is not a coincidence). Cool the slider to 3000 K, a light bulb filament, and watch the peak slide into the infrared, which is why incandescent bulbs waste most of their energy as heat.
5. Symbolic math: let the computer do calculus¶
Our final import is sympy, an entire computer algebra system:
The dashed “peak” line obeys Wien’s law, . In 1900 deriving it took real work; sympy differentiates Planck’s law and finds the root for you. One standard physics trick first: substitute the dimensionless variable , so Planck’s law becomes a clean scale-free shape and every temperature collapses onto one curve:
That output is not a decimal: sympy solved the transcendental equation exactly, in terms of the Lambert W function. Turned into numbers, it hands us Wien’s constant:
The result matches the dashed line in the plot above and scipy’s tabulated constant to four digits. You will use the same maximize-by-differentiating trick later to locate maxima of probability densities.
6. Complex numbers: a 30-second preview¶
Quantum wavefunctions are complex-valued, so Python treats complex numbers as first-class citizens (1j is the imaginary unit). Take :
The quantity is exactly how probability densities are built from wavefunctions in Chapter 3.
How this page works
The Python cells are marimo cells executed while the site is built, so the page loads instantly with correct static output. The first time you move a control, a Python runtime (Pyodide, Python compiled to WebAssembly) loads in the background with NumPy, SciPy, Matplotlib, and SymPy, and from then on every cell reruns locally in your browser. The button at the top of the page opens the whole thing as an editable notebook if you want to change the code itself.
- Bohr, N. (1913). On the Constitution of Atoms and Molecules. Philosophical Magazine, 26(151), 1–25. 10.1080/14786441308634955
- Planck, M. (1901). Über das Gesetz der Energieverteilung im Normalspectrum. Annalen Der Physik, 309(3), 553–563. 10.1002/andp.19013090310