Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 16.2 — Jupyter Notebooks and the Experiment Workflow
Python · Example 1 of 2

A toy kernel shows the hidden-state trap

Read the comments, predict each printed line, then run it.

A notebook is a document of code cells that share one running Python process, which makes it excellent for exploring data and risky for anything you need to repeat. The workflow is to explore in a notebook, then move the working code into modules with tests, seeds and locked dependencies.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write a function run_in_order(cells) that runs a list of code strings in a fresh shared namespace and returns the namespace.

02

Write a function sample(seed) that returns five dice rolls from its own seeded generator, and show that equal seeds match.

03

Write a function to_requirements(reqs) that turns a dict of name to version into sorted pinned lines.

Explain it without notes

01

What is a kernel, and why does it cause the hidden-state problem?

02

How do you make a notebook result trustworthy and shareable?

03

Describe a workflow that takes an experiment from a notebook to production code.

04

Two data scientists run the same notebook and get different numbers. List the causes you would check, in order.

A toy kernel shows the hidden-state trap
Sign in to run this example in your browser.

Expected output

cell 2: price is 100
cell 2 again: 500 -> discounted 450.0
discounted is still 450.0 but price is 50