diff --git a/jupyter-book/preprocessing_visualization/quality_control.ipynb b/jupyter-book/preprocessing_visualization/quality_control.ipynb
index 133e8fc6..1d3f9530 100644
--- a/jupyter-book/preprocessing_visualization/quality_control.ipynb
+++ b/jupyter-book/preprocessing_visualization/quality_control.ipynb
@@ -965,54 +965,103 @@
]
},
{
- "cell_type": "code",
- "execution_count": 7,
- "id": "8ce9c2f0",
+ "cell_type": "markdown",
+ "id": "1c468d05",
"metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Requirement already satisfied: ipywidgets in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (8.1.5)\n",
- "Requirement already satisfied: comm>=0.1.3 in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from ipywidgets) (0.2.1)\n",
- "Requirement already satisfied: ipython>=6.1.0 in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from ipywidgets) (8.30.0)\n",
- "Requirement already satisfied: traitlets>=4.3.1 in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from ipywidgets) (5.14.3)\n",
- "Requirement already satisfied: widgetsnbextension~=4.0.12 in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from ipywidgets) (4.0.13)\n",
- "Requirement already satisfied: jupyterlab-widgets~=3.0.12 in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from ipywidgets) (3.0.13)\n",
- "Requirement already satisfied: decorator in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from ipython>=6.1.0->ipywidgets) (5.1.1)\n",
- "Requirement already satisfied: jedi>=0.16 in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from ipython>=6.1.0->ipywidgets) (0.19.2)\n",
- "Requirement already satisfied: matplotlib-inline in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from ipython>=6.1.0->ipywidgets) (0.1.6)\n",
- "Requirement already satisfied: prompt-toolkit<3.1.0,>=3.0.41 in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from ipython>=6.1.0->ipywidgets) (3.0.43)\n",
- "Requirement already satisfied: pygments>=2.4.0 in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from ipython>=6.1.0->ipywidgets) (2.15.1)\n",
- "Requirement already satisfied: stack-data in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from ipython>=6.1.0->ipywidgets) (0.2.0)\n",
- "Requirement already satisfied: typing-extensions>=4.6 in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from ipython>=6.1.0->ipywidgets) (4.12.2)\n",
- "Requirement already satisfied: pexpect>4.3 in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from ipython>=6.1.0->ipywidgets) (4.8.0)\n",
- "Requirement already satisfied: parso<0.9.0,>=0.8.4 in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from jedi>=0.16->ipython>=6.1.0->ipywidgets) (0.8.4)\n",
- "Requirement already satisfied: ptyprocess>=0.5 in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from pexpect>4.3->ipython>=6.1.0->ipywidgets) (0.7.0)\n",
- "Requirement already satisfied: wcwidth in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from prompt-toolkit<3.1.0,>=3.0.41->ipython>=6.1.0->ipywidgets) (0.2.5)\n",
- "Requirement already satisfied: executing in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from stack-data->ipython>=6.1.0->ipywidgets) (0.8.3)\n",
- "Requirement already satisfied: asttokens in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from stack-data->ipython>=6.1.0->ipywidgets) (2.0.5)\n",
- "Requirement already satisfied: pure-eval in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from stack-data->ipython>=6.1.0->ipywidgets) (0.2.2)\n",
- "Requirement already satisfied: six in /Users/seohyon/miniconda3/envs/book/lib/python3.11/site-packages (from asttokens->stack-data->ipython>=6.1.0->ipywidgets) (1.16.0)\n",
- "Note: you may need to restart the kernel to use updated packages.\n"
- ]
- }
- ],
"source": [
- "%pip install ipywidgets"
+ "# Test: Quiz with pure html\n",
+ "## multiple choice question"
]
},
{
"cell_type": "code",
- "execution_count": 11,
- "id": "71b4d643",
- "metadata": {},
+ "execution_count": 84,
+ "id": "b9926ce3",
+ "metadata": {
+ "tags": [
+ "remove_input"
+ ]
+ },
"outputs": [
{
"data": {
"text/html": [
- "
"
@@ -1107,111 +1248,328 @@
"source": [
"from IPython.display import HTML, display\n",
"\n",
- "display(HTML(''))\n",
- "\n",
- "import ipywidgets as widgets\n",
- "from IPython.display import clear_output, display\n",
- "\n",
- "# Questions, options, and correct answers\n",
- "questions = [\n",
- " {\n",
- " \"question\": \"What is the capital of France?\",\n",
- " \"options\": [\"Berlin\", \"Madrid\", \"Paris\", \"Rome\"],\n",
- " \"answer\": \"Paris\",\n",
- " },\n",
- " {\n",
- " \"question\": \"Which programming language is primarily used for data analysis?\",\n",
- " \"options\": [\"Python\", \"C++\", \"Java\", \"Ruby\"],\n",
- " \"answer\": \"Python\",\n",
- " },\n",
- " {\n",
- " \"question\": \"What is the largest planet in the Solar System?\",\n",
- " \"options\": [\"Earth\", \"Mars\", \"Jupiter\", \"Saturn\"],\n",
- " \"answer\": \"Jupiter\",\n",
- " },\n",
- "]\n",
- "\n",
- "\n",
- "# Function to display the quiz\n",
- "def create_quiz():\n",
- " score = 0 # Track the score\n",
- " question_index = 0 # Current question index\n",
- "\n",
- " # Widgets for the quiz\n",
- " question_label = widgets.Label()\n",
- " options = widgets.RadioButtons(\n",
- " description=\"\", style={\"description_width\": \"initial\"}\n",
- " )\n",
- " submit_button = widgets.Button(description=\"Submit\")\n",
- " feedback_label = widgets.Label(value=\"\")\n",
- " next_button = widgets.Button(description=\"Next\")\n",
- " next_button.disabled = True # Disabled until the current question is answered\n",
- "\n",
- " # Callback for submit button\n",
- " def on_submit(change):\n",
- " nonlocal score\n",
- " if options.value == questions[question_index][\"answer\"]:\n",
- " feedback_label.value = \"Correct! 🎉\"\n",
- " score += 1\n",
- " else:\n",
- " feedback_label.value = f\"Incorrect. The correct answer is {questions[question_index]['answer']}.\"\n",
- " submit_button.disabled = True\n",
- " next_button.disabled = False\n",
- "\n",
- " # Callback for next button\n",
- " def on_next(change):\n",
- " nonlocal question_index\n",
- " question_index += 1\n",
- " if question_index < len(questions):\n",
- " load_question()\n",
- " else:\n",
- " show_final_score()\n",
- "\n",
- " # Load a question\n",
- " def load_question():\n",
- " feedback_label.value = \"\"\n",
- " submit_button.disabled = False\n",
- " next_button.disabled = True\n",
- " question_label.value = questions[question_index][\"question\"]\n",
- " options.options = questions[question_index][\"options\"]\n",
- "\n",
- " # Show the final score\n",
- " def show_final_score():\n",
- " clear_output()\n",
- " display(widgets.Label(value=f\"Your final score is: {score}/{len(questions)}\"))\n",
- "\n",
- " # Set up the initial question\n",
- " load_question()\n",
- "\n",
- " # Display all widgets\n",
- " display(question_label, options, submit_button, feedback_label, next_button)\n",
- "\n",
- " # Connect button callbacks\n",
- " submit_button.on_click(on_submit)\n",
- " next_button.on_click(on_next)\n",
- "\n",
- "\n",
- "# Run the quiz\n",
- "create_quiz()\n",
- "\n",
- "display(HTML(\"
\"))"
+ "\n",
+ "def multiple_choice_question(\n",
+ " question_id,\n",
+ " question,\n",
+ " options,\n",
+ " correct_answer,\n",
+ " bg_color=\"#ffadad\",\n",
+ " text_color=\"white\",\n",
+ " answer_color=\"red\",\n",
+ "):\n",
+ " options_html = \"\"\n",
+ " for option in options:\n",
+ " options_html += f\"\"\"\n",
+ " \n",
+ " {option}\n",
+ " \n",
+ " \"\"\"\n",
+ "\n",
+ " html_code = f\"\"\"\n",
+ " \n",
+ "\n",
+ " \n",
+ "
{question}
\n",
+ " {options_html}\n",
+ "
\n",
+ "\n",
+ " \n",
+ "
\n",
+ " ✔ Correct Answer: {correct_answer}\n",
+ "
\n",
+ "
\n",
+ "\n",
+ " \n",
+ " \"\"\"\n",
+ " display(HTML(html_code))\n",
+ "\n",
+ "\n",
+ "multiple_choice_question(\n",
+ " \"q1\",\n",
+ " \"What is the capital of France?\",\n",
+ " [\"Paris\", \"London\", \"Berlin\", \"Madrid\"],\n",
+ " \"Paris\",\n",
+ ")\n",
+ "\n",
+ "multiple_choice_question(\n",
+ " \"q2\",\n",
+ " \"Which planet is known as the Red Planet?\",\n",
+ " [\"Earth\", \"Mars\", \"Venus\", \"Jupiter\"],\n",
+ " \"Mars\",\n",
+ ")\n",
+ "\n",
+ "multiple_choice_question(\n",
+ " \"q3\",\n",
+ " \"Who wrote 'Hamlet'?\",\n",
+ " [\"Shakespeare\", \"Hemingway\", \"Austen\", \"Dickens\"],\n",
+ " \"Shakespeare\",\n",
+ ")"
]
},
{
- "cell_type": "code",
- "execution_count": 12,
- "id": "2d67783c",
+ "cell_type": "markdown",
+ "id": "a8c1849e",
"metadata": {},
+ "source": [
+ "## flip card"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 78,
+ "id": "f567ab22",
+ "metadata": {
+ "tags": [
+ "remove_input"
+ ]
+ },
"outputs": [
{
"data": {
"text/html": [
"\n",
- "\n"
+ " \n",
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ " This is a simple question\n",
+ "
\n",
+ "
\n",
+ " a simple answer\n",
+ "
\n",
+ "
\n",
+ "
\n",
+ " \n",
+ " Q: This is a simple question
\n",
+ " Answer: a simple answer
\n",
+ " \n",
+ " "
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ " \n",
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ " this is another question, but with long answer\n",
+ "
\n",
+ "
\n",
+ " back_font_size must be adjusted for long answers\n",
+ "
\n",
+ "
\n",
+ "
\n",
+ " \n",
+ " Q: this is another question, but with long answer
\n",
+ " Answer: back_font_size must be adjusted for long answers
\n",
+ " \n",
+ " "
],
"text/plain": [
""
@@ -1222,14 +1580,122 @@
}
],
"source": [
- "display(\n",
- " HTML(\"\"\"\n",
- "\n",
- "\"\"\")\n",
+ "def flip_card(\n",
+ " question_id,\n",
+ " question,\n",
+ " answer,\n",
+ " front_color=\"#ffadad\",\n",
+ " back_color=\"#a8d480\",\n",
+ " text_color=\"white\",\n",
+ " front_font_size=20,\n",
+ " back_font_size=20,\n",
+ "):\n",
+ " html_code = f\"\"\"\n",
+ " \n",
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ " {question}\n",
+ "
\n",
+ "
\n",
+ " {answer}\n",
+ "
\n",
+ "
\n",
+ "
\n",
+ " \n",
+ " Q: {question}
\n",
+ " Answer: {answer}
\n",
+ " \n",
+ " \"\"\"\n",
+ " display(HTML(html_code))\n",
+ "\n",
+ "\n",
+ "# Example Flip Cards with Different Back Font Sizes\n",
+ "flip_card(\"q1\", \"This is a simple question\", \"a simple answer\")\n",
+ "flip_card(\n",
+ " \"q2\",\n",
+ " \"this is another question, but with long answer\",\n",
+ " \"back_font_size must be adjusted for long answers\",\n",
+ " front_font_size=20,\n",
+ " back_font_size=15,\n",
")"
]
}