diff --git a/.gitignore b/.gitignore index 234b452..d227f21 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .ipynb_checkpoints/* -testfile.txt \ No newline at end of file +testfile.txt +_output +.jupyterlite.doit.db diff --git a/Basics.ipynb b/Basics.ipynb index 58861d4..a9d9b32 100644 --- a/Basics.ipynb +++ b/Basics.ipynb @@ -514,22 +514,6 @@ "### _Example:_ Print type of a variable" ] }, - { - "cell_type": "markdown", - "id": "98edd5e0", - "metadata": { - "editable": false, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, - "source": [ - "The `print` function which outputs text or variable values to the screen so they are visible while the program runs.\n", - "\n", - "This is one way to allow you to see what your program is doing as it executes." - ] - }, { "cell_type": "code", "execution_count": null, @@ -592,23 +576,26 @@ "tags": [] }, "source": [ - "### _Example:_ Try to assign the data types at the following qr code" + "### _Quiz:_ For a given variable name: What type of data is stored in there?\n", + "Execute the cell to start the quiz" ] }, { - "cell_type": "markdown", - "id": "8dc654b8", + "cell_type": "code", + "execution_count": null, + "id": "84c08047-1384-4734-9e44-81aea50035ed", "metadata": { - "editable": false, + "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, + "outputs": [], "source": [ - "Try not to overthink. If something is ambiguous pick what fits best\n", - "\n", - "![QRCode](images/qr_question1.png)" + "%pip install jupyterquiz\n", + "from quizzes import display_quiz\n", + "display_quiz(\"quizzes/datatypes.json\")" ] }, { diff --git a/Basics_filled.ipynb b/Basics_filled.ipynb index a0eebb8..58c6b3c 100644 --- a/Basics_filled.ipynb +++ b/Basics_filled.ipynb @@ -755,22 +755,6 @@ "### _Example:_ Print type of a variable" ] }, - { - "cell_type": "markdown", - "id": "98edd5e0", - "metadata": { - "editable": false, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, - "source": [ - "The `print` function which outputs text or variable values to the screen so they are visible while the program runs.\n", - "\n", - "This is one way to allow you to see what your program is doing as it executes." - ] - }, { "cell_type": "code", "execution_count": null, @@ -871,62 +855,26 @@ "tags": [] }, "source": [ - "### _Example:_ Try to assign the data types at the following qr code" + "### _Quiz:_ For a given variable name: What type of data is stored in there?\n", + "Execute the cell to start the quiz" ] }, { - "cell_type": "markdown", - "id": "8dc654b8", + "cell_type": "code", + "execution_count": null, + "id": "84c08047-1384-4734-9e44-81aea50035ed", "metadata": { - "editable": false, + "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, + "outputs": [], "source": [ - "Try not to overthink. If something is ambiguous pick what fits best\n", - "\n", - "![QRCode](images/qr_question1.png)" - ] - }, - { - "cell_type": "markdown", - "id": "6d81fa96", - "metadata": { - "editable": false, - "slideshow": { - "slide_type": "skip" - }, - "tags": [] - }, - "source": [ - "##### _Notes:_" - ] - }, - { - "cell_type": "markdown", - "id": "6fc5a2b1", - "metadata": { - "editable": false, - "slideshow": { - "slide_type": "skip" - }, - "tags": [] - }, - "source": [ - "Questions behind QR Code\n", - "Assign a type to the variable names\n", - "1. name\n", - " - str obviously\n", - "2. items_in_stock\n", - " - usually means a number -> int\n", - "3. pressure_bar\n", - " - if you have different physical units for a size put the unit into the name. Say you also have pressure_torr\n", - "4. is_student\n", - " - bool\n", - "5. participants\n", - " - is an ambiguous name (names, number, there are some) if this can happen, name the variable differently." + "%pip install jupyterquiz\n", + "from quizzes import display_quiz\n", + "display_quiz(\"quizzes/datatypes.json\")" ] }, { diff --git a/environment.yml b/environment.yml index 65e3241..d309629 100644 --- a/environment.yml +++ b/environment.yml @@ -5,6 +5,6 @@ dependencies: - jupyter - jupyterlab - jupyterlab-deck +- jupyterquiz - python -- jupyter_contrib_nbextensions -- jupytext \ No newline at end of file +- jupyter_contrib_nbextensions \ No newline at end of file diff --git a/images/qr_question1.png b/images/qr_question1.png deleted file mode 100644 index 1456aed..0000000 Binary files a/images/qr_question1.png and /dev/null differ diff --git a/quizzes/__init__.py b/quizzes/__init__.py new file mode 100644 index 0000000..c022054 --- /dev/null +++ b/quizzes/__init__.py @@ -0,0 +1,18 @@ +import jupyterquiz + +def display_quiz(json_path): + colors = { + '--jq-multiple-choice-bg': '#66295B', + '--jq-mc-button-bg': '#fafafa', + '--jq-mc-button-border': '#66295B', + '--jq-many-choice-bg': '#66295B', + '--jq-numeric-bg': '#66295B', + '--jq-numeric-input-bg': '#fafafa', + '--jq-numeric-input-label': '#2d2d2d', + '--jq-numeric-input-shadow': '#4A1D42', + '--jq-string-bg': '#66295B', + '--jq-incorrect-color': '#c80202', + '--jq-correct-color': '#5CB85C', + '--jq-link-color': '#B8A7D6' + } + return jupyterquiz.display_quiz(json_path, border_radius=1, colors=colors) diff --git a/quizzes/datatypes.json b/quizzes/datatypes.json new file mode 100644 index 0000000..9b7a57b --- /dev/null +++ b/quizzes/datatypes.json @@ -0,0 +1,132 @@ +[ + { + "question": "Variable named name", + "type": "multiple_choice", + "answers": [ + { + "answer": "str", + "correct": true, + "feedback": "Correct. A person's name is text data, so it should be a string." + }, + { + "answer": "int", + "correct": false, + "feedback": "Numbers can't properly represent names." + }, + { + "answer": "float", + "correct": false, + "feedback": "Names aren't decimal numbers." + }, + { + "answer": "bool", + "correct": false, + "feedback": "A name isn't just True or False." + } + ] + }, + { + "question": "Variable named num_items_in_stock", + "type": "multiple_choice", + "answers": [ + { + "answer": "int", + "correct": true, + "feedback": "Correct. Stock counts are whole numbers (integers). Usually you would not track 3.5 items in stock." + }, + { + "answer": "str", + "correct": false, + "feedback": "While you could store it as text, numbers allow mathematical operations like adding or subtracting stock." + }, + { + "answer": "float", + "correct": false, + "feedback": "Stock counts usually are whole numbers, not decimals." + }, + { + "answer": "bool", + "correct": false, + "feedback": "The name implies a quantity, not just yes or no." + } + ] + }, + { + "question": "Variable named height_m", + "type": "multiple_choice", + "answers": [ + { + "answer": "float", + "correct": true, + "feedback": "Correct. Height measurements typically have decimal precision (like 1.75m). The '_m' suffix indicates the unit (meters). If you also have height_ft or height_cm, putting the unit in the variable name keeps them distinct." + }, + { + "answer": "str", + "correct": false, + "feedback": "You need to perform calculations with height values, like comparisons or conversions." + }, + { + "answer": "int", + "correct": false, + "feedback": "While technically possible if you only need whole meters, measurements typically require decimal precision. Float is the conventional choice for physical measurements." + }, + { + "answer": "bool", + "correct": false, + "feedback": "This represents a measurement value, not yes or no." + } + ] + }, + { + "question": "Variable named is_student", + "type": "multiple_choice", + "answers": [ + { + "answer": "bool", + "correct": true, + "feedback": "Correct. The 'is_' prefix is a Python convention for boolean values. Someone either is or isn't a student." + }, + { + "answer": "str", + "correct": false, + "feedback": "While you could use 'yes' or 'no' strings, bool is the Pythonic choice for true or false values." + }, + { + "answer": "int", + "correct": false, + "feedback": "Don't use 0 and 1 for true and false - use bool instead." + }, + { + "answer": "float", + "correct": false, + "feedback": "This is a yes or no question, not a number." + } + ] + }, + { + "question": "Variable named participants

This variable name is ambiguous. Select all types that could be reasonable interpretations, then discuss: how would you rename this variable to be clearer?", + "type": "many_choice", + "answers": [ + { + "answer": "int", + "correct": true, + "feedback": "Yes, this could work if you're counting the number of participants. Better name: participant_count or num_participants." + }, + { + "answer": "str", + "correct": true, + "feedback": "Yes, this could work if it's a text description like 'students and teachers'. Better name would depend on what you're describing - perhaps participant_description." + }, + { + "answer": "float", + "correct": false, + "feedback": "This is unlikely - you can't have fractional participants. The main issue is that the variable name doesn't clearly communicate its purpose." + }, + { + "answer": "bool", + "correct": false, + "feedback": "This doesn't fit - the name doesn't follow the 'is_' or 'has_' pattern typically used for booleans (like has_participants)." + } + ] + } +] \ No newline at end of file