> For the complete documentation index, see [llms.txt](https://mindengage.gitbook.io/mindengage-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mindengage.gitbook.io/mindengage-docs/code-example.md).

# Code Example

Turns a paragraph of explanation into runnable / editable code snippets (with optional exercises).

The Code Example Builder is a no-code generator that lets you drop hands-on programming directly into any lesson. Highlight an explanatory paragraph, give the snippet a clear visual name, and choose between **Try it Yourself** (open-ended sandbox) or **Code Challenge** (gap-filled exercise with hidden solution). Click **Create** and the builder spins up a self-contained Pyodide workspace with Run / Reset controls, optional solution reveal, and a floating **Viz Card** you can position anywhere in the document. Because everything executes client-side, learners can experiment, debug, and test ideas instantly—without installing Python, configuring servers, or leaving the page.

### Workflow

1. **Highlight** text in *Lesson Preview* → **Code Example** modal appears.
2. You may edit the selected content or add new concept for coding exercise.

   <figure><img src="https://1630048059-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz5vwxN0ZYDFxp9SGEstf%2Fuploads%2FHOeuJHCNNvJlQzSRY0pc%2Fmindengage-docs.png?alt=media&amp;token=05b50236-7c32-42e3-bb57-da427ba80e57" alt=""><figcaption></figcaption></figure>
3. **Pick** a coding type and tweak the prompt if needed.
4. **Create** – a floating **Viz Card** appears; click **Place Visualization** to embed the snippet.

<figure><img src="https://1630048059-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz5vwxN0ZYDFxp9SGEstf%2Fuploads%2FStjaX8RxGL7e3KVRjIys%2Fimage.png?alt=media&amp;token=daaadd9b-8926-460e-8ae3-8f39bc4a3aee" alt="" width="563"><figcaption></figcaption></figure>

### Coding Type Selector

The **Coding Type** drop-down lets authors decide what kind of interactive Python experience they want to embed in a lesson.\
It appears in the exercise-creation form (see screenshot above) and offers two mutually exclusive modes:

| Option              | When to choose it                                                                                 | What learners see                                                                                           |
| ------------------- | ------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| **Try it Yourself** | Quick “sandbox” experiments, worked examples the learner can tweak, or exploratory REPL missions. | A single editable code cell, **Run** / **Reset** buttons, and a console-style output pane.                  |
| **Code Challenge**  | Structured practice problems in which the learner must complete missing lines or debug code.      | Starter code containing `### TODO` gaps, **Run**, **Reset**, and **Show Solution / Hide Solution** buttons. |

#### Authoring guidelines

* **Choose “Try it Yourself”** for concept demonstrations, live explorations, or anything that benefits from free-form experimentation.
* **Choose “Code Challenge”** for formative assessment, mastery checks, or debugging tasks where you want learners to fill blanks or compare against a reference solution.

***

####
