Interactive Python
Some websites let learners execute Python directly in the browser. This is useful for short exploratory tasks where immediate feedback is more important than distributing a full notebook.
Browser-executed cells
The imol course site uses configured Quarto live/Pyodide support for cells written like this:
```{pyodide}
1 + 2 + 3
```
When rendered by that configured project, the cell becomes an interactive Python area in the HTML page. Like shown below
These blocks rely on pyodide which is a Python distribution for the browser based on WebAssembly. This allows Python to run in the browser without the need for a server as it uses the local machine (be it a laptop, desktop or a cellphone).
pyodide cells require the appropriate Quarto extension and output format. Adding the syntax to an unrelated course repository does not by itself enable browser execution.
Exercises
The Quarto Live extension enables adding exercises with accompanying solution code, such that exercises are automatically checked. See Quarto Live: Creating Exercises for more information. Below is an example of such an exercise.
Example
Fill in the blank so the result is 10
When to use interactive Python
Interactive cells suit small calculations, quick data exploration, and low-setup introductions to programming. Prefer rendered notebooks or a normal execution workflow when learners need:
- Larger code workflows or many interdependent cells.
- Installed packages not supported by the in-browser environment.
- Persistent files, saved work, or assessment submission.
More information
See Embedded Interactive Computation for more information about Quarto Live and additional use-case examples.