Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing quizzes to fix issue #49 #57

Merged
merged 4 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 145 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,158 @@
"content = [\n",
" {\n",
" \"question\": (\n",
" \"If you need to represent 'hello world', in Python you would use ...\"\n",
" \"What are the recommended sections of the Python standard library working \"\n",
" \"with file paths?\"\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\": \"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",
" \"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. This \"\n",
" \"is missing the separator, too!\",\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",
" \"What method would you use to convert a relative path to an absolute path, \"\n",
" \"normalising it in the process?\"\n",
" ),\n",
" \"type\": \"multiple_choice\",\n",
" \"answers\": [\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. This returns an absolute path without \"\n",
" \"normalisation.\",\n",
" },\n",
" {\n",
" \"answer\": \"parent()\",\n",
" \"correct\": False,\n",
" \"feedback\": \"Incorrect. parent() is used to obtain the parent \"\n",
" \"directory.\",\n",
" },\n",
" ],\n",
" },\n",
"]\n",
"\n",
"\n",
"display_quiz(content, colors=\"fdsp\")"
]
}
Expand Down
172 changes: 167 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,177 @@
"\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 set 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 are much harder to read than \"\n",
" \"well-formatted code examples.\"\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