Approximating the Value of Pi
30-minute lesson · module-lab-approximating-pi
You are previewing this course as a guest
Read anything and run any exercise you like. It all runs in your own browser, so nothing here is saved: no XP, no progress, and the AI tutor needs an account. Sign in and your work starts counting.
Approximating the Value of Pi
30-minute lesson · module-lab-approximating-pi
- Use Monte Carlo simulation — random sampling — to estimate a value.
- Apply the accumulator pattern to count "inside-the-circle" hits.
- Reason about how sample size affects approximation accuracy.
Source attribution
Status: adapted
How to Think Like a Computer Scientist: Interactive Edition — source · Labs / Approximating the Value of Pi
Adaptation notes. Original lab used turtle graphics to visualize dart throws. We skip the turtle visualization (PyTutor AI does not include the turtle chapter) and focus on the math: random sampling, the accumulator pattern, and convergence. The simulation is pure Python; no extra libraries needed.
License notes. Original lab is GNU FDL 1.3 (Brad Miller and David Ranum, 2011). No verbatim text from the original is reproduced here.