puzzle-widget
A Jupyter widget where students drag scrambled code lines into the correct order, built on anywidget.
Tag a cell %%puzzle <result>; every line below it becomes a draggable row,
shuffled so the student starts from a scrambled order. Drag (or focus a
row and press the arrow keys) to reorder them -- the widget re-runs the
current order after every move and shows a checkmark once it produces
<result>.
import puzzle_widget # registers the %%puzzle cell magic
%%puzzle 15
a = 10
b = 5
a + b
Write the lines in whatever order reads best -- the correct one included:
the widget shuffles them before showing them, and never starts from an order
that already produces <result>. Dragging them back into a working order
produces 15 and the widget shows "✓ Correct!".
The shuffle is seeded, so a given puzzle always starts in the same scrambled
order -- every student sees the same starting point, and a puzzle you tested
looks the same when you teach it. Pass seed= to PuzzleWidget for a
different one.
Installation
# pixi
pixi workspace channel add munch-group
pixi add puzzle-widget
# conda
conda install -c munch-group puzzle-widget
# pip
pip install puzzle-widget
Writing a puzzle
<result>is a Python literal (a number, string, list, ...), parsed withast.literal_eval-- not an arbitrary expression, since the puzzle runs in its own isolated namespace, not the notebook's.- Every line must be a complete, independent, non-indented statement. A
puzzle can't contain multi-line blocks (
if/for/def/...) that need to stay attached to each other, since any permutation of the lines has to at least parse -- only the values it produces should depend on the order. - The result is the value of the last line, which must be a bare
expression (
a + b, or a variable's name on its own) -- exactly like a notebook cell only shows output for a trailing expression, not for an assignment. If the puzzle's final step istotal = a + b, add atotalline after it so there's a value to check.
You can also build a widget directly from a list of lines:
from puzzle_widget import PuzzleWidget
PuzzleWidget(["a = 10", "b = 5", "a + b"], expected=15)
Documentation
Full docs live at munch-group.org/puzzle-widget.
Development
This repo is managed with pixi:
pixi run install-dev # editable install into the pixi environment
pixi run test # run the pytest suite
pixi run docs # execute the documentation notebooks
pixi run api # build the quartodoc API reference
License
MIT
Metadata
Release files for puzzle-widget 0.1.21
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| puzzle_widget-0.1.21.tar.gz | 132.1 kB | Without provenance | Details for puzzle_widget-0.1.21.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| puzzle_widget-0.1.21-py3-none-any.whl | Python 3 | none | any | Details for puzzle_widget-0.1.21-py3-none-any.whl |
Total release size: 144.4 kB
Release files / puzzle_widget-0.1.21.tar.gz
| Download URL | puzzle_widget-0.1.21.tar.gz |
|---|---|
| Size | 132.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
69a5641b5e46d9e716ccd5ff69a1e9e13b80b13f101d5c6e956c5e9dae439ca7
|
|
BLAKE2b-256 checksum How to use checksums |
96d660f20a863d9e8cfed6d6684af2ae094b4106dd956b47280a8a0232ff163d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / puzzle_widget-0.1.21-py3-none-any.whl
| Download URL | puzzle_widget-0.1.21-py3-none-any.whl |
|---|---|
| Size | 12.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e565f78d998289b7a044d3b6ce5daee204289b43b819bc1218083ee07b9a60cf
|
|
BLAKE2b-256 checksum How to use checksums |
b29202d0d65de0f9d7ee44932fcc8dcbdc520fa34c9c2f0f0e8a75a1c31427f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for puzzle-widget 0.1.21
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.