Hiding "spoilers" (answers) cells

Hi, I’m working on some Jupyter based training material that it’s supposed to be used as self guided support for some classes. It has some exaplanatory markdown, some code examples in code cells that students can use, and some practice exercises. I want to provide answers for the exercises , which I’m doing with a detail tags. To give you a small (artificial example):

[Markdown Cell] Write some code that asks the user to enter a sentence, and print back the last word in that sentence.

[Code cell]

# Enter your code here
pass

[Markdown cell]

<details>

<summary>Answers</summary>

You can use split() to separate words, and negative indexing to get the last value:
```python
sentence = input("Enter a sentence:")
print(sentence.split()[-1])
```
</details>

Using the <details> tag like this allows the students to avoid the “spoiler” until they have tried solving it. However the snippet of Python code that I enter is not runnable, if they want to try it they need to copy and paste it into their own cell.

If I put the answer in a code cell, it’s automatically visible. I’ve seen some tips about how to hide all input cells, but I only want to do this selectively (some code cells are examples and should be visible by default, but code cells shouldn’t be). Is there a way to do this?

1 Like

I use the collapsible headings extension as a simple way of hiding multiple cells, code and markdown, beneath a collapsed header. Quick and easy, though it does rely on the student user have the extension installed and enabled.

1 Like

I’ll take a look, that might work. Thanks!

I have used the magic command %load for this purpose. It loads the content of a text file into a code cell. What I do is to create a folder with solutions for each exercise and load them where necessary.

It looks like the following.

# Uncomment the following line to see the solution
# %load ./snippets/solution_exercise.py
5 Likes

That worked really well, thanks!

1 Like

It’s a cool thing to do indeed and ups the level of engagement. How did it work out for you?

Btw we created a platform for doing this called Mynerva.
We call such self guided t codices. Check out https://youtu.be/R84L-BQcjHw if interested to see how it is different from jupyter. We have taught thousands of students using this.

See mynerva.ii/courses/register for a demo. Use “JULIACON2020” (no quotes) to see how it looks and feels. Try the one on neural nets. If you’re interested in trying the authoring platform ping us via mynerva

1 Like