Skip to content

Commit 18198a2

Browse files
authored
Merge pull request #48 from DurhamARC-Training/jupyterquiz
Merge Jupyterquiz branch
2 parents 4fea4d5 + 0c6b263 commit 18198a2

7 files changed

Lines changed: 175 additions & 88 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.ipynb_checkpoints/*
2-
testfile.txt
2+
testfile.txt
3+
_output
4+
.jupyterlite.doit.db

Basics.ipynb

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -514,22 +514,6 @@
514514
"### _<ins>Example</ins>:_ Print type of a variable"
515515
]
516516
},
517-
{
518-
"cell_type": "markdown",
519-
"id": "98edd5e0",
520-
"metadata": {
521-
"editable": false,
522-
"slideshow": {
523-
"slide_type": ""
524-
},
525-
"tags": []
526-
},
527-
"source": [
528-
"The `print` function which outputs text or variable values to the screen so they are visible while the program runs.\n",
529-
"\n",
530-
"This is one way to allow you to see what your program is doing as it executes."
531-
]
532-
},
533517
{
534518
"cell_type": "code",
535519
"execution_count": null,
@@ -592,23 +576,26 @@
592576
"tags": []
593577
},
594578
"source": [
595-
"### _<ins>Example</ins>:_ Try to assign the data types at the following qr code"
579+
"### _<ins>Quiz</ins>:_ For a given variable name: What type of data is stored in there?\n",
580+
"Execute the cell to start the quiz"
596581
]
597582
},
598583
{
599-
"cell_type": "markdown",
600-
"id": "8dc654b8",
584+
"cell_type": "code",
585+
"execution_count": null,
586+
"id": "84c08047-1384-4734-9e44-81aea50035ed",
601587
"metadata": {
602-
"editable": false,
588+
"editable": true,
603589
"slideshow": {
604590
"slide_type": ""
605591
},
606592
"tags": []
607593
},
594+
"outputs": [],
608595
"source": [
609-
"Try not to overthink. If something is ambiguous pick what fits best\n",
610-
"\n",
611-
"![QRCode](images/qr_question1.png)"
596+
"%pip install jupyterquiz\n",
597+
"from quizzes import display_quiz\n",
598+
"display_quiz(\"quizzes/datatypes.json\")"
612599
]
613600
},
614601
{

Basics_filled.ipynb

Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -755,22 +755,6 @@
755755
"### _<ins>Example</ins>:_ Print type of a variable"
756756
]
757757
},
758-
{
759-
"cell_type": "markdown",
760-
"id": "98edd5e0",
761-
"metadata": {
762-
"editable": false,
763-
"slideshow": {
764-
"slide_type": ""
765-
},
766-
"tags": []
767-
},
768-
"source": [
769-
"The `print` function which outputs text or variable values to the screen so they are visible while the program runs.\n",
770-
"\n",
771-
"This is one way to allow you to see what your program is doing as it executes."
772-
]
773-
},
774758
{
775759
"cell_type": "code",
776760
"execution_count": null,
@@ -871,62 +855,26 @@
871855
"tags": []
872856
},
873857
"source": [
874-
"### _<ins>Example</ins>:_ Try to assign the data types at the following qr code"
858+
"### _<ins>Quiz</ins>:_ For a given variable name: What type of data is stored in there?\n",
859+
"Execute the cell to start the quiz"
875860
]
876861
},
877862
{
878-
"cell_type": "markdown",
879-
"id": "8dc654b8",
863+
"cell_type": "code",
864+
"execution_count": null,
865+
"id": "84c08047-1384-4734-9e44-81aea50035ed",
880866
"metadata": {
881-
"editable": false,
867+
"editable": true,
882868
"slideshow": {
883869
"slide_type": ""
884870
},
885871
"tags": []
886872
},
873+
"outputs": [],
887874
"source": [
888-
"Try not to overthink. If something is ambiguous pick what fits best\n",
889-
"\n",
890-
"![QRCode](images/qr_question1.png)"
891-
]
892-
},
893-
{
894-
"cell_type": "markdown",
895-
"id": "6d81fa96",
896-
"metadata": {
897-
"editable": false,
898-
"slideshow": {
899-
"slide_type": "skip"
900-
},
901-
"tags": []
902-
},
903-
"source": [
904-
"##### _<ins>Notes:</ins>_"
905-
]
906-
},
907-
{
908-
"cell_type": "markdown",
909-
"id": "6fc5a2b1",
910-
"metadata": {
911-
"editable": false,
912-
"slideshow": {
913-
"slide_type": "skip"
914-
},
915-
"tags": []
916-
},
917-
"source": [
918-
"Questions behind QR Code\n",
919-
"Assign a type to the variable names\n",
920-
"1. name\n",
921-
" - str obviously\n",
922-
"2. items_in_stock\n",
923-
" - usually means a number -> int\n",
924-
"3. pressure_bar\n",
925-
" - if you have different physical units for a size put the unit into the name. Say you also have pressure_torr\n",
926-
"4. is_student\n",
927-
" - bool\n",
928-
"5. participants\n",
929-
" - is an ambiguous name (names, number, there are some) if this can happen, name the variable differently."
875+
"%pip install jupyterquiz\n",
876+
"from quizzes import display_quiz\n",
877+
"display_quiz(\"quizzes/datatypes.json\")"
930878
]
931879
},
932880
{

environment.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ dependencies:
55
- jupyter
66
- jupyterlab
77
- jupyterlab-deck
8+
- jupyterquiz
89
- python
9-
- jupyter_contrib_nbextensions
10-
- jupytext
10+
- jupyter_contrib_nbextensions

images/qr_question1.png

-4.38 KB
Binary file not shown.

quizzes/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import jupyterquiz
2+
3+
def display_quiz(json_path):
4+
colors = {
5+
'--jq-multiple-choice-bg': '#66295B',
6+
'--jq-mc-button-bg': '#fafafa',
7+
'--jq-mc-button-border': '#66295B',
8+
'--jq-many-choice-bg': '#66295B',
9+
'--jq-numeric-bg': '#66295B',
10+
'--jq-numeric-input-bg': '#fafafa',
11+
'--jq-numeric-input-label': '#2d2d2d',
12+
'--jq-numeric-input-shadow': '#4A1D42',
13+
'--jq-string-bg': '#66295B',
14+
'--jq-incorrect-color': '#c80202',
15+
'--jq-correct-color': '#5CB85C',
16+
'--jq-link-color': '#B8A7D6'
17+
}
18+
return jupyterquiz.display_quiz(json_path, border_radius=1, colors=colors)

quizzes/datatypes.json

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
[
2+
{
3+
"question": "Variable named <code>name</code>",
4+
"type": "multiple_choice",
5+
"answers": [
6+
{
7+
"answer": "str",
8+
"correct": true,
9+
"feedback": "Correct. A person's name is text data, so it should be a string."
10+
},
11+
{
12+
"answer": "int",
13+
"correct": false,
14+
"feedback": "Numbers can't properly represent names."
15+
},
16+
{
17+
"answer": "float",
18+
"correct": false,
19+
"feedback": "Names aren't decimal numbers."
20+
},
21+
{
22+
"answer": "bool",
23+
"correct": false,
24+
"feedback": "A name isn't just True or False."
25+
}
26+
]
27+
},
28+
{
29+
"question": "Variable named <code>num_items_in_stock</code>",
30+
"type": "multiple_choice",
31+
"answers": [
32+
{
33+
"answer": "int",
34+
"correct": true,
35+
"feedback": "Correct. Stock counts are whole numbers (integers). Usually you would not track 3.5 items in stock."
36+
},
37+
{
38+
"answer": "str",
39+
"correct": false,
40+
"feedback": "While you could store it as text, numbers allow mathematical operations like adding or subtracting stock."
41+
},
42+
{
43+
"answer": "float",
44+
"correct": false,
45+
"feedback": "Stock counts usually are whole numbers, not decimals."
46+
},
47+
{
48+
"answer": "bool",
49+
"correct": false,
50+
"feedback": "The name implies a quantity, not just yes or no."
51+
}
52+
]
53+
},
54+
{
55+
"question": "Variable named <code>height_m</code>",
56+
"type": "multiple_choice",
57+
"answers": [
58+
{
59+
"answer": "float",
60+
"correct": true,
61+
"feedback": "Correct. Height measurements typically have decimal precision (like 1.75m). The '_m' suffix indicates the unit (meters). If you also have <code>height_ft</code> or <code>height_cm</code>, putting the unit in the variable name keeps them distinct."
62+
},
63+
{
64+
"answer": "str",
65+
"correct": false,
66+
"feedback": "You need to perform calculations with height values, like comparisons or conversions."
67+
},
68+
{
69+
"answer": "int",
70+
"correct": false,
71+
"feedback": "While technically possible if you only need whole meters, measurements typically require decimal precision. Float is the conventional choice for physical measurements."
72+
},
73+
{
74+
"answer": "bool",
75+
"correct": false,
76+
"feedback": "This represents a measurement value, not yes or no."
77+
}
78+
]
79+
},
80+
{
81+
"question": "Variable named <code>is_student</code>",
82+
"type": "multiple_choice",
83+
"answers": [
84+
{
85+
"answer": "bool",
86+
"correct": true,
87+
"feedback": "Correct. The 'is_' prefix is a Python convention for boolean values. Someone either is or isn't a student."
88+
},
89+
{
90+
"answer": "str",
91+
"correct": false,
92+
"feedback": "While you could use 'yes' or 'no' strings, bool is the Pythonic choice for true or false values."
93+
},
94+
{
95+
"answer": "int",
96+
"correct": false,
97+
"feedback": "Don't use 0 and 1 for true and false - use bool instead."
98+
},
99+
{
100+
"answer": "float",
101+
"correct": false,
102+
"feedback": "This is a yes or no question, not a number."
103+
}
104+
]
105+
},
106+
{
107+
"question": "Variable named <code>participants</code><br><br><em>This variable name is ambiguous. Select all types that could be reasonable interpretations, then discuss: how would you rename this variable to be clearer?</em>",
108+
"type": "many_choice",
109+
"answers": [
110+
{
111+
"answer": "int",
112+
"correct": true,
113+
"feedback": "Yes, this could work if you're counting the number of participants. Better name: <code>participant_count</code> or <code>num_participants</code>."
114+
},
115+
{
116+
"answer": "str",
117+
"correct": true,
118+
"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 <code>participant_description</code>."
119+
},
120+
{
121+
"answer": "float",
122+
"correct": false,
123+
"feedback": "This is unlikely - you can't have fractional participants. The main issue is that the variable name doesn't clearly communicate its purpose."
124+
},
125+
{
126+
"answer": "bool",
127+
"correct": false,
128+
"feedback": "This doesn't fit - the name doesn't follow the 'is_' or 'has_' pattern typically used for booleans (like <code>has_participants</code>)."
129+
}
130+
]
131+
}
132+
]

0 commit comments

Comments
 (0)