Plotting a Sine Wave

30-minute lesson · module-lab-sine-wave

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.

Sign in

Plotting a Sine Wave

30-minute lesson · module-lab-sine-wave

  • Use the `math` module — specifically `math.sin` and `math.radians`.
  • Build parallel lists of x and y values across a range with a list comprehension.
  • Distinguish degrees from radians and convert between them.

Source attribution

Status: adapted

How to Think Like a Computer Scientist: Interactive Edition source · Labs / Plotting a sine Wave

Adaptation notes. Original lab used the turtle module to plot the wave point-by-point. We replace turtle with returning the (x, y) sample pairs. A follow-up note shows how to feed the same data into matplotlib for an actual visual plot (Pyodide supports matplotlib via micropip). The math — `math.sin(math.radians(angle))` — is preserved.

License notes. Original lab is GNU FDL 1.3 (Brad Miller and David Ranum, 2011). No verbatim text from the original is reproduced here.