# HIDDEN
# Clear previously defined variables
%reset -f
Interactive Questions¶
nbinteract also provides built-in methods to easily create multiple choice and short answer questions.
import nbinteract as nbi
nbinteract.multiple_choice¶
nbinteract.multiple_choice
takes a question, a list of possible answer choices, and the correct answer. Clicking the buttons shows whether the choice was correct.
nbi.multiple_choice(question="What is 10 + 2 * 5?",
choices=['12', '60', '20'],
answers=2)
nbi.multiple_choice(question="Select all prime numbers.",
choices=['12', '3', '31'],
answers=[1, 2])
nbinteract.short_answer¶
nbinteract.short_answer
takes a question and an answer.
The answer can either be a string, a list of strings, or a function that returns True
when called with the user's input. If the function errors, an error message will be displayed.
nbi.short_answer('What is 1+1?', answers='2', explanation='1+1 is 2')
nbi.short_answer('Enter the first name of a member of the Beatles.',
['John', 'Paul', 'George', 'Ringo'])
nbi.short_answer('Enter an even number.', lambda x: int(x) % 2 == 0)