【发布时间】:2020-07-05 21:02:47
【问题描述】:
在 Jupyter Notebooks 中进行离线作业
VSCODE v. 1.46.1 | Python v3.8.2 | Jupyter Notebook v. 6.0.3
我正在尝试使用 jupyter 笔记本构建一门课程,其中我有兴趣在笔记本中的课程结束后分配作业。我希望笔记本在学生运行时与他们互动。为了开发这个,我使用 VSCODE。
有兴趣的可以加入GitHub的私人项目
我使用ipywidgets 让我的笔记本具有交互性。
面临的问题:
能够提出问题但看不到输出
MCQ 定义单元
##Basic mcq
from ipywidgets import widgets, Layout, Box, GridspecLayout
def create_multipleChoice_widget(description, options, correct_answer, hint):
if correct_answer not in options:
options.append(correct_answer)
correct_answer_index = options.index(correct_answer)
radio_options = [(words, i) for i, words in enumerate(options)]
alternativ = widgets.RadioButtons(
options = radio_options,
description = '',
disabled = False,
indent = False,
align = 'center',
)
description_out = widgets.Output(layout=Layout(width='auto'))
with description_out:
print(description)
feedback_out = widgets.Output()
def check_selection(b):
a = int(alternativ.value)
if a==correct_answer_index:
s = '\x1b[6;30;42m' + "correct" + '\x1b[0m' +"\n"
else:
s = '\x1b[5;30;41m' + "try again" + '\x1b[0m' +"\n"
with feedback_out:
feedback_out.clear_output()
print(s)
return
check = widgets.Button(description="check")
check.on_click(check_selection)
hint_out = widgets.Output()
def hint_selection(b):
with hint_out:
print(hint)
with feedback_out:
feedback_out.clear_output()
print(hint)
hintbutton = widgets.Button(description="hint")
hintbutton.on_click(hint_selection)
return widgets.VBox([description_out,
alternativ,
widgets.HBox([hintbutton, check]), feedback_out],
layout=Layout(display='flex',
flex_flow='column',
align_items='stretch',
width='auto'))
问题单元:
test = create_multipleChoice_widget('1.What version of Python is used throughout this course?',['1.x','2.x','2.7','3.x'],'3.x','[hint]: Refer Lesson Again')
输出单元:
【问题讨论】:
标签: python visual-studio-code jupyter-notebook