How to do a lab

Five minutes, with pictures. Everything runs in your browser: nothing to install.

Each lab is a notebook: a page that mixes short instructions with small pieces of Python code that you run, change and finish yourself. It runs inside your web browser, on the course website. Labs are practice: not graded, nothing to submit.

1 · Open the lab

On the lab’s page, click ▶︎ Start this lab in your browser. The first time, wait 10 to 20 seconds while Python loads into your browser.

The lab as it opens: your files on the left, the notebook on the right.{fig-alt=“A JupyterLite window: the file list on the left with the lab notebooks, the Lab 1 notebook on the right, starting with a folded”About this lab” box and the story of the lab”}

  • Left: your files. Right: the notebook.
  • The notebook is made of cells: text cells (instructions) and code cells (grey boxes).
  • Use a computer, with Chrome, Edge or Firefox. A phone is too small.

2 · Run the cells, from the top

Click a code cell, then press Shift + Enter. The cell runs and the next one is selected. (Or click ▶ in the toolbar.)

  • [ ] not run yet · [*] running · [5] done.
  • Always run the cells in order, from the top. Later cells use what earlier cells made.

The first code cells of Lab 1 after running: the setup cell is numbered and Python is ready

After running the first cells: each finished cell shows a number in brackets.

3 · Three levels

Every task’s title shows its level, in hot peppers: the more peppers, the spicier.

  • 🌶 Core: done together in class. Everyone does these.
  • 🌶🌶 Extend: optional, at home, with hints.
  • 🌶🌶🌶 Challenge: optional, open-ended, for the curious.

4 · Your turn: finish the code

Where it says Do:, there is a code cell with a line # YOUR CODE HERE. Replace that line with your code.

A code cell outlined in orange: the simulate function with its docstring, a few prepared lines, and a comment YOUR CODE HERE before return None

A “Do” cell: the function is started for you; you write the part marked YOUR CODE HERE.
  • Keep the function’s name and inputs: later cells call it by that name.
  • The text in triple quotes (the docstring) says exactly what the function must return.

5 · Check your work

The cell right after each function checks it. Run it.

  • checks passed means you are on track.
  • A red box means not yet. Read the last line: it says what is wrong.

A check cell that has run and shows a red error box ending in AssertionError: complete simulate() first

A check that fails: the last line, “complete simulate() first”, says what to do.

6 · Try other numbers

Many Core cells have their numbers on the first line, marked # try other values. Change them and run the cell again, with the check below it: the best way to see what a model does.

  1. Change the first line, for example n_cars, C_a, C_b = 10, 0.36, 0.85.
  2. Run that cell, and its check below.

Lab 1 cell A3 with its first line, n_cars, C_a, C_b = 8, 0.40, 0.80, outlined in orange

A cell with its numbers on the first line: change them and run the cell again.

7 · Where your work is kept

Your work is saved in this browser, on this computer.

  • Come back on the same computer and the same browser, and your code is still there. But Python starts fresh: run the cells again from the top (Run → Run All Cells; it stops at the first check that fails).
  • Moving to another computer: File → Download, then upload the file there with the upload arrow above the file list.
  • Do not work in a private or incognito window: everything is lost when it closes.
  • Clearing your browser’s data deletes your work. Download a copy first.

The File menu open, listing Save Notebook, Rename Notebook, Download and other items

The File menu, with Download near the bottom.

When something goes wrong

What you see What to do
NameError: name 'np' is not defined (or another name) You skipped cells. Run → Run All Above Selected Cell, then try again.
A cell stays at [*] Kernel → Restart Kernel, then Run → Run All Above Selected Cell.
complete ... first Finish the function in the cell above.
Run All Cells stops halfway It stopped at a check that fails: read its last line.
The page stays blank Reload the page. Use Chrome, Edge or Firefox on a computer.
My work is gone It lives in the browser you used. Open the lab in that same browser on the same computer.

Still stuck? Ask in class, or email the instructor with the lab number and a screenshot.