Skip to content

Commit

Permalink
Add missing quizzes to fix #49.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcofo21 committed Nov 28, 2024
1 parent 16e803f commit 999af56
Show file tree
Hide file tree
Showing 2 changed files with 307 additions and 10 deletions.
146 changes: 141 additions & 5 deletions src/epp_topics/python_basics/pathlib/objectives_materials.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,154 @@
"content = [\n",
" {\n",
" \"question\": (\n",
" \"If you need to represent 'hello world', in Python you would use ...\"\n",
" \"Which of the following rules should you follow when working with file \"\n",
" \"paths?\"\n",
" ),\n",
" \"type\": \"many_choice\",\n",
" \"answers\": [\n",
" {\n",
" \"answer\": \"Always use pathlib Path objects instead of strings.\",\n",
" \"correct\": True,\n",
" \"feedback\": \"Correct.\",\n",
" },\n",
" {\n",
" \"answer\": \"Copy the full path that you get by right-clicking on the\"\n",
" \" file in the file explorer and paste it in your code.\",\n",
" \"correct\": False,\n",
" \"feedback\": \"Incorrect. Avoid hardcoding paths outside the project.\",\n",
" },\n",
" {\n",
" \"answer\": \"\"\"Make sure to not use backslashes (\"\\\\\") in paths.\"\"\",\n",
" \"correct\": True,\n",
" \"feedback\": \"Correct. Use forward slashes ('/') for paths.\",\n",
" },\n",
" ],\n",
" },\n",
" {\n",
" \"question\": (\n",
" \"What would the correct way be to join the directory 'datasets' with the \"\n",
" \"file 'data.csv' using pathlib?\"\n",
" ),\n",
" \"type\": \"multiple_choice\",\n",
" \"answers\": [\n",
" {\n",
" \"answer\": \"Path('datasets') / 'data.csv'\",\n",
" \"correct\": True,\n",
" \"feedback\": \"Correct. This is the correct way to join paths in\"\n",
" \"pathlib.\",\n",
" },\n",
" {\n",
" \"answer\": \"'datasets' + 'data.csv'\",\n",
" \"correct\": False,\n",
" \"feedback\": \"Incorrect. String addition is not the right method.\",\n",
" },\n",
" {\n",
" \"answer\": \"os.path.join('datasets', 'data.csv')\",\n",
" \"correct\": False,\n",
" \"feedback\": (\n",
" \"Incorrect. Although this would work, pathlib is the recommended \"\n",
" \"method.\"\n",
" ),\n",
" },\n",
" ],\n",
" },\n",
" {\n",
" \"question\": (\n",
" \"You are writing code in a script file inside some folder, and you want to \"\n",
" \"load an example.csv dataset located in a folder called data, which is in \"\n",
" \"the same directory as the script. What is the correct way to load the \"\n",
" \"dataset?\"\n",
" ),\n",
" \"type\": \"multiple_choice\",\n",
" \"answers\": [\n",
" {\n",
" \"answer\": \"Path() / 'example.csv'\",\n",
" \"correct\": False,\n",
" \"feedback\": (\n",
" \"Incorrect. This would look for the dataset in the same directory \"\n",
" \"as the script.\"\n",
" ),\n",
" },\n",
" {\n",
" \"answer\": \"Path() / 'data' / 'example.csv'\",\n",
" \"correct\": True,\n",
" \"feedback\": (\n",
" \"Correct. This is the correct way to load the dataset from the\"\n",
" \" data.\"\n",
" ),\n",
" },\n",
" {\n",
" \"answer\": \"./data/example.csv\",\n",
" \"correct\": False,\n",
" \"feedback\": (\n",
" \"Incorrect. This would work, but pathlib is the recommended method.\"\n",
" ),\n",
" },\n",
" ],\n",
" },\n",
" {\n",
" \"question\": (\n",
" \"Which module in Python is recommended for working with file paths?\"\n",
" ),\n",
" \"type\": \"multiple_choice\",\n",
" \"answers\": [\n",
" {\n",
" \"answer\": \"os\",\n",
" \"correct\": False,\n",
" \"feedback\": (\n",
" \"Incorrect. While the os module can handle paths, pathlib is \"\n",
" \"preferred for portability.\"\n",
" ),\n",
" },\n",
" {\n",
" \"answer\": \"pathlib\",\n",
" \"correct\": True,\n",
" \"feedback\": \"Correct. pathlib is the recommended module for file \"\n",
" \"paths.\",\n",
" },\n",
" {\n",
" \"answer\": \"pandas\",\n",
" \"correct\": False,\n",
" \"feedback\": (\n",
" \"Incorrect. pandas is used for data manipulation, not file paths.\"\n",
" ),\n",
" },\n",
" ],\n",
" },\n",
" {\n",
" \"question\": (\n",
" \"What method would you use to convert a relative path to an absolute path?\"\n",
" ),\n",
" \"type\": \"multiple_choice\",\n",
" \"answers\": [\n",
" {\"answer\": \"A string\", \"correct\": True, \"feedback\": \"Correct.\"},\n",
" {\"answer\": \"A float\", \"correct\": False, \"feedback\": \"Incorrect.\"},\n",
" {\"answer\": \"An integer\", \"correct\": False, \"feedback\": \"Incorrect.\"},\n",
" {\"answer\": \"A Boolean\", \"correct\": False, \"feedback\": \"Incorrect.\"},\n",
" {\n",
" \"answer\": \"resolve()\",\n",
" \"correct\": True,\n",
" \"feedback\": (\n",
" \"Correct. resolve() converts a relative path to an absolute path.\"\n",
" ),\n",
" },\n",
" {\n",
" \"answer\": \"join()\",\n",
" \"correct\": False,\n",
" \"feedback\": \"Incorrect. join() is not a method in pathlib.\",\n",
" },\n",
" {\n",
" \"answer\": \"absolute()\",\n",
" \"correct\": False,\n",
" \"feedback\": \"Incorrect. There is no method named absolute() in \"\n",
" \"pathlib.\",\n",
" },\n",
" {\n",
" \"answer\": \"parent()\",\n",
" \"correct\": False,\n",
" \"feedback\": \"Incorrect. parent() is used to move up a directory.\",\n",
" },\n",
" ],\n",
" },\n",
"]\n",
"\n",
"\n",
"display_quiz(content, colors=\"fdsp\")"
]
}
Expand Down
171 changes: 166 additions & 5 deletions src/epp_topics/python_basics/tracebacks/objectives_materials.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,176 @@
"\n",
"content = [\n",
" {\n",
" \"question\": (\"What does a Python traceback help you to do?\"),\n",
" \"type\": \"multiple_choice\",\n",
" \"answers\": [\n",
" {\n",
" \"answer\": \"Run your code faster.\",\n",
" \"correct\": False,\n",
" \"feedback\": (\n",
" \"Incorrect. A traceback helps you find errors, not speed up code.\"\n",
" ),\n",
" },\n",
" {\n",
" \"answer\": \"Localize and understand errors.\",\n",
" \"correct\": True,\n",
" \"feedback\": (\n",
" \"Correct. A traceback shows where and why an error occurred.\"\n",
" ),\n",
" },\n",
" {\n",
" \"answer\": \"Optimize memory usage.\",\n",
" \"correct\": False,\n",
" \"feedback\": (\n",
" \"Incorrect. Tracebacks provide error information, not\"\n",
" \"optimizations.\"\n",
" ),\n",
" },\n",
" {\n",
" \"answer\": \"Improve variable naming.\",\n",
" \"correct\": False,\n",
" \"feedback\": (\n",
" \"Incorrect. Tracebacks do not suggest improvements to variable \"\n",
" \"names.\"\n",
" ),\n",
" },\n",
" ],\n",
" },\n",
" {\n",
" \"question\": (\n",
" \"Which part of the traceback should you read first to diagnose the error?\"\n",
" ),\n",
" \"type\": \"multiple_choice\",\n",
" \"answers\": [\n",
" {\n",
" \"answer\": \"The top of the traceback.\",\n",
" \"correct\": False,\n",
" \"feedback\": \"Incorrect. Tracebacks can be very long.\",\n",
" },\n",
" {\n",
" \"answer\": \"The middle of the traceback.\",\n",
" \"correct\": False,\n",
" \"feedback\": \"Incorrect.\",\n",
" },\n",
" {\n",
" \"answer\": \"The bottom of the traceback.\",\n",
" \"correct\": True,\n",
" \"feedback\": (\n",
" \"Correct. Starting at the bottom is often the quickest way to \"\n",
" \"get information on the error. You can then scroll up to find \"\n",
" \"where the error originated.\"\n",
" ),\n",
" },\n",
" {\n",
" \"answer\": \"It doesn't matter.\",\n",
" \"correct\": False,\n",
" \"feedback\": (\n",
" \"Incorrect. Reading order can speed up the debugging process.\"\n",
" ),\n",
" },\n",
" ],\n",
" },\n",
" {\n",
" \"question\": (\n",
" \"Which exception type occurs if you use a list as a dictionary key?\"\n",
" ),\n",
" \"type\": \"multiple_choice\",\n",
" \"answers\": [\n",
" {\n",
" \"answer\": \"ValueError\",\n",
" \"correct\": False,\n",
" \"feedback\": (\n",
" \"Incorrect. ValueError relates to invalid function inputs.\"\n",
" ),\n",
" },\n",
" {\n",
" \"answer\": \"KeyError\",\n",
" \"correct\": False,\n",
" \"feedback\": (\n",
" \"Incorrect. KeyError relates to missing keys in a dictionary.\"\n",
" ),\n",
" },\n",
" {\n",
" \"answer\": \"TypeError\",\n",
" \"correct\": True,\n",
" \"feedback\": (\n",
" \"Correct. TypeError occurs when using an unhashable type as a key.\"\n",
" ),\n",
" },\n",
" {\n",
" \"answer\": \"ImportError\",\n",
" \"correct\": False,\n",
" \"feedback\": (\n",
" \"Incorrect. ImportError relates to issues with importing modules.\"\n",
" ),\n",
" },\n",
" ],\n",
" },\n",
" {\n",
" \"question\": (\"What should you be looking for when reading a traceback?\"),\n",
" \"type\": \"many_choice\",\n",
" \"answers\": [\n",
" {\n",
" \"answer\": \"What type of error occurred.\",\n",
" \"correct\": True,\n",
" \"feedback\": \"Correct. You can find this at the bottom or top-left.\",\n",
" },\n",
" {\n",
" \"answer\": \"Where the error occurred.\",\n",
" \"correct\": True,\n",
" \"feedback\": \"Correct. You can find this in the middle of the traceback.\"\n",
" \"Sometimes there will be calls to many script files, often also from\"\n",
" \"libraries you are using. Make sure to first find where the error\"\n",
" \"originated in your code.\",\n",
" },\n",
" {\n",
" \"answer\": \"What caused the error.\",\n",
" \"correct\": True,\n",
" \"feedback\": \"Correct. You will find this at the end of the traceback. \"\n",
" \"However, the message you will find will often not be immediately\"\n",
" \"clear to you. Don't worry about this, we will learn how to tackle\"\n",
" \"this better while working on debugging.\",\n",
" },\n",
" ],\n",
" },\n",
" {\n",
" \"question\": (\n",
" \"If you need to represent 'hello world', in Python you would use ...\"\n",
" \"What is the proper way to ask for help when encountering a traceback?\"\n",
" ),\n",
" \"type\": \"multiple_choice\",\n",
" \"answers\": [\n",
" {\"answer\": \"A string\", \"correct\": True, \"feedback\": \"Correct.\"},\n",
" {\"answer\": \"A float\", \"correct\": False, \"feedback\": \"Incorrect.\"},\n",
" {\"answer\": \"An integer\", \"correct\": False, \"feedback\": \"Incorrect.\"},\n",
" {\"answer\": \"A Boolean\", \"correct\": False, \"feedback\": \"Incorrect.\"},\n",
" {\n",
" \"answer\": (\n",
" \"Explain the task, show what you tried, and share a minimal \"\n",
" \"example.\"\n",
" ),\n",
" \"correct\": True,\n",
" \"feedback\": (\n",
" \"Correct. Providing details and examples helps others assist you.\"\n",
" ),\n",
" },\n",
" {\n",
" \"answer\": \"Send a screenshot with no explanation.\",\n",
" \"correct\": False,\n",
" \"feedback\": (\n",
" \"Incorrect. Screenshots make it harder to diagnose the issue.\"\n",
" ),\n",
" },\n",
" {\n",
" \"answer\": \"Ask via direct message without context.\",\n",
" \"correct\": False,\n",
" \"feedback\": (\n",
" \"Incorrect. Asking publicly with context is more helpful.\"\n",
" ),\n",
" },\n",
" {\n",
" \"answer\": \"Say, 'Python does not work on my computer.'\",\n",
" \"correct\": False,\n",
" \"feedback\": (\n",
" \"Incorrect. This gives no useful information to help with\"\n",
" \" debugging.\"\n",
" ),\n",
" },\n",
" ],\n",
" },\n",
"]\n",
Expand Down

0 comments on commit 999af56

Please sign in to comment.