Episode 3 — The Copy-Paste Soup

Programming with Python · Tutorial 03

Kevin has pasted the same receipt code fourteen times, and a ten-cent price change just cost him an afternoon of hunting down copies. In this notebook you give him the cure: the function, code you write once and call anywhere. You’ll write functions with parameters and return values, learn why a function can’t secretly change your variables (scope), give a parameter a default, and bundle data with behavior in a first class. It ends in the Tip Calculator Championship, where the whole class throws weird receipts at each other’s tip functions to see whose survives.

Work on the notebook

Open in browser Open in molab

Open in browser (recommended): runs entirely on your machine, in this tab: no account, no installation, and after it loads no internet is needed.

ImportantHow your work is saved (read this once)

Your progress lives in this browser tab. If you reload the page (Cmd/Ctrl + R) your work is still there. But if you close the tab and open the link again later, you start from a clean notebook. There is no cross-device sync in the browser, and clearing browser data or private mode also wipes it.

So: download your .py before you leave (menu → Download → Download Python code). That download is the only guaranteed copy. Handing in files works exactly like this in the checkpoints, so you get to practice the motion every week. Note: a downloaded .py is for submission and backup. You can’t upload it back into the browser editor.

Open in molab: marimo’s free cloud (account required). Your copy saves to your account and reopens on any device. Choose this if you know you’ll switch computers or want to be certain nothing is lost. Optional: nothing graded ever requires it.