Hiding code for interactive exercises in Jupyter notebooks in bytecode files

I would like to implement interactive exercises in Jupyter notebooks by evaluating text entered into ipythonwidget’s text inputs and then displaying feedback.

If I place the code for evaluating the text input (which basically contains the solution to the exercise) directly into the notebook or into an external module, users (students) can quickly find it.

Therefore, I thought of placing the code for evaluating the answers into separate files and compile them to bytecode.
Would this be sufficient to hide the solution?
(The exercises are not that difficult that it’s worth reverse engineering/disassembling the bytecode.)

Is there another way to hide the code for evaluating the text input from users (students)?

1 Like

You could probably write a custom Jupyter server extension with a new web endpoint.
By submitting the user’s text input, the custom endpoint can be called, which evaluates the solution and returns feedback.

If there are only “static” solutions (e.g., numbers), it may also be possible to hash the solution and compare the hashed user text input with the hashed solution.

2 Likes

Thanks, that sounds not trivial, but feasible.

Hashing is already not trivial for numerical input considering accepting rounded answers (like for roots, exponentials or trigonometric functions) and would not scale to algebraic expressions.

1 Like