interactive-code directive#
The interactive-code directive creates an interactive code editor where students can write and execute code directly in the browser.
Basic usage#
```{interactive-code}
:lang: python
for i in range(3):
print(i)
```
Prediction mode#
Use :predict: to ask students to predict the output before running the code:
```{interactive-code}
:lang: python
:predict:
x = 5
print(x * 2)
```
Options#
Option |
Meaning |
Default |
|---|---|---|
|
Programming language |
|
|
Enable prediction mode — students guess output first |
off |
Tips#
The optional positional argument (e.g.
intro-example) gives the block a stable ID for cross-referencing.Code in the body becomes the initial content of the editor.