SIRF-Exercises icon indicating copy to clipboard operation
SIRF-Exercises copied to clipboard

Better way to have answers to exercises

Open KrisThielemans opened this issue 1 year ago • 3 comments

@gschramm has the following tip:

We discussed having code block hints that users could unhide if they are stuck, an easy way to do this would be to have another folder in the repository called something like snippets then the code # %load './snippets/01_exA.py' would load the contents of 01_exA.py into the jupyter notebook cell. We usually give instructions like Uncomment the following line and run the cell to see the solution, to run the lines you'll need to run the cell a second time

KrisThielemans avatar May 02 '24 09:05 KrisThielemans

This is done in most notebooks not (not yet the MR ones)

KrisThielemans avatar Jun 28 '25 20:06 KrisThielemans

Another option could be to simply hide cells (https://jupyterbook.org/en/stable/interactive/hiding.html). One advantage would be that the code is already there and hence the notebooks could be run automatically. Currently we are still running the notebooks by hand whenever there is an update to SIRF. It would be nice to move this to an automatic github action which checks that there is at least no error with the current SIRF method.

ckolbPTB avatar Jun 30 '25 09:06 ckolbPTB

Another option could be to simply hide cells (https://jupyterbook.org/en/stable/interactive/hiding.html). One advantage would be that the code is already there and hence the notebooks could be run automatically. Currently we are still running the notebooks by hand whenever there is an update to SIRF. It would be nice to move this to an automatic github action which checks that there is at least no error with the current SIRF method.

that seems a very interesting option to me. I think the only potential issue is that users that don't need the predefined solutions would have to create a new cell with their solutions. And when running all cells it might be that they execute both solutions (theirs and the pre-defined one) which could lead to unexpected side effects.

another more advanced solution would be to use nbgrader that allows to define "solution cells" and to export notebooks with and without the solutions. nbgrader also allows to test notebooks. I have used that last year for a few assignments at my courses which worked very well.

gschramm avatar Jul 02 '25 09:07 gschramm