Jupyter widget where students drag scrambled code lines into the correct order (the %%puzzle cell magic)
Project description
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.
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 + b
b = 5
a = 10
The student sees the three lines in that scrambled order; dragging a = 10
and b = 5 above a + b produces 15 and the widget shows "✓ Correct!".
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: either a bare expression
(
a + b) or a simple assignment (total = a + b), read back from the namespace afterward.
You can also build a widget directly from a list of lines:
from puzzle_widget import PuzzleWidget
PuzzleWidget(["a + b", "b = 5", "a = 10"], 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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file puzzle_widget-0.1.8.tar.gz.
File metadata
- Download URL: puzzle_widget-0.1.8.tar.gz
- Upload date:
- Size: 79.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8b99e9dbc0a5d8d17bb0cde344f116cb73e9d89d1556dbb895de5017c3143d6
|
|
| MD5 |
55add5f7a1d61845ff06a4c209b77502
|
|
| BLAKE2b-256 |
14c7ae6ac69292abe8d0ad5df314b72d018da5191eeaad519bc0ba362f58774f
|
File details
Details for the file puzzle_widget-0.1.8-py3-none-any.whl.
File metadata
- Download URL: puzzle_widget-0.1.8-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6b586840eb9932bc2f4e9155ef1eef648a5514d2bf519b38d78edd833c88501
|
|
| MD5 |
6bb0a03a63fb8e8ae943af3e96d55c5e
|
|
| BLAKE2b-256 |
782b8851857ee162f500c27abb65b7d226c56f4654e51d97df1585fcdebcb475
|