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.
# Enter your code here pass
<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>
<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?