Code
amount = 0.004
volume = 0.2
amount / volume
print(volume)0.2
Course material may show code for reading, execute code while rendering, or produce interactive notebooks. The syntax distinguishes displayed examples from executable cells.
Use an ordinary fenced block when code should be read or copied but not run by Quarto:
```python
def concentration(amount, volume):
return amount / volume
```This provides syntax highlighting only, the cell above for example produces the following syntax-highlighted code
def concentration(amount, volume):
return amount / volumeIn order to include executable Python code in a document the project must have a Python execution engine, this means
pixi.tomlpixi.toml.An example with a mimimal dependency set is shown below
[dependencies]
quarto = ">=1.9.38,<2"
python = "==3.12"
[pypi-dependencies]
jupyter = ">=1.1.1, <2"Additional packages can be added using
pixi add <package-name> --pypiWhen the project is configured with a Python execution engine, braces mark a cell for execution:
```{python}
amount = 0.004
volume = 0.2
amount / volume
print(volume)
```This code will be executed during rendering, producing highlighted code and output like below
amount = 0.004
volume = 0.2
amount / volume
print(volume)0.2
Execution behavior, cached outputs, and output formats are controlled by document front matter and _quarto.yml.
For new projects with the strip-solution teaching-tools extension, mark conditional cells with the preferred teaching option:
```{python}
#| teaching: exercise
#| eval: false
result = ... # learner completes this cell
```
```{python}
#| teaching: solution
result = 0.004 / 0.2
result
```
With teaching.show-solutions: false, the student render removes the solution cell. With teaching.show-solutions: true, the instructor render removes the exercise cell. Mark student scaffold cells with #| eval: false when they should not execute; the extension does not do this automatically.
The extension still accepts legacy #| exercise: true and #| solution: true options for existing repositories. Use the teaching option for new authoring.
When editing executable material, verify that: