{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": { "id": "7vcVhbkFS81g", "nbgrader": { "grade": false, "locked": true, "solution": false } }, "source": [ "# Exercises" ] }, { "attachments": {}, "cell_type": "markdown", "id": "b30cda82", "metadata": {}, "source": [ "::: {note}\n", "You don't need to worry about using Interactive Jupyter Notebooks for these exercises. You can simply ignore the rocket icon ({fa}`rocket`) and go ahead to answer the questions using the knowledge you've gained from the chapter. Have fun!\n", "::: " ] }, { "cell_type": "code", "execution_count": 1, "id": "2a982fe0", "metadata": { "tags": [ "remove-input" ] }, "outputs": [], "source": [ "import json\n", "from jupyterquiz import display_quiz\n", "#load all questions json file\n", "with open(\"01.json\", \"r\") as file:\n", " questions = json.load(file)\n", "\n", "questions = [[q] for q in questions]" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": { "id": "Pq9kETciS3VO", "nbgrader": { "grade": false, "locked": true, "solution": false } }, "source": [ "## Exercise 1.2.2\n", "\n", "What is the type of the result of the following expression $3 + 1.5 + 4?$\n", "* `str`\n", "* `int`\n", "* `float`\n" ] }, { "cell_type": "code", "execution_count": 28, "id": "96306ad3", "metadata": { "tags": [ "remove-input" ] }, "outputs": [ { "data": { "text/html": [ "
3 + 1.5 + 4
?\", \"type\": \"many_choice\", \"answers\": [{\"answer\": \"str
\", \"correct\": false, \"feedback\": \"I hope not.\"}, {\"answer\": \" int
\", \"correct\": false, \"feedback\": \"I hope not.\"}, {\"answer\": \" float
\", \"correct\": true, \"feedback\": \"Correct.\"}]}];\n // Make a random ID\nfunction makeid(length) {\n var result = [];\n var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n var charactersLength = characters.length;\n for (var i = 0; i < length; i++) {\n result.push(characters.charAt(Math.floor(Math.random() * charactersLength)));\n }\n return result.join('');\n}\n\n// Choose a random subset of an array. Can also be used to shuffle the array\nfunction getRandomSubarray(arr, size) {\n var shuffled = arr.slice(0), i = arr.length, temp, index;\n while (i--) {\n index = Math.floor((i + 1) * Math.random());\n temp = shuffled[index];\n shuffled[index] = shuffled[i];\n shuffled[i] = temp;\n }\n return shuffled.slice(0, size);\n}\n\nfunction printResponses(responsesContainer) {\n var responses=JSON.parse(responsesContainer.dataset.responses);\n var stringResponses='IMPORTANT!To preserve this answer sequence for submission, when you have finalized your answers: 'r'
of the sentence 'Hello engineer!'
"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "2528ef76",
"metadata": {
"tags": [
"remove-input"
]
},
"outputs": [
{
"data": {
"text/html": [
" `r'
of the sentence `Hello engineer!'
?\", \"type\": \"many_choice\", \"answers\": [{\"answer\": \"0
\", \"correct\": false, \"feedback\": \"I hope not.\"}, {\"answer\": \" 13
\", \"correct\": true, \"feedback\": \"Correct.\"}, {\"answer\": \" 12
\", \"correct\": false, \"feedback\": \"I hope not.\"}]}];\n // Make a random ID\nfunction makeid(length) {\n var result = [];\n var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n var charactersLength = characters.length;\n for (var i = 0; i < length; i++) {\n result.push(characters.charAt(Math.floor(Math.random() * charactersLength)));\n }\n return result.join('');\n}\n\n// Choose a random subset of an array. Can also be used to shuffle the array\nfunction getRandomSubarray(arr, size) {\n var shuffled = arr.slice(0), i = arr.length, temp, index;\n while (i--) {\n index = Math.floor((i + 1) * Math.random());\n temp = shuffled[index];\n shuffled[index] = shuffled[i];\n shuffled[i] = temp;\n }\n return shuffled.slice(0, size);\n}\n\nfunction printResponses(responsesContainer) {\n var responses=JSON.parse(responsesContainer.dataset.responses);\n var stringResponses='IMPORTANT!To preserve this answer sequence for submission, when you have finalized your answers: my_complex_number
of Complex type and assign a $3 + 2i$ value to it. For that you will have to Google a bit. Try to look for something like \"Python complex variables\". Python is very popular and you will be able to find everything you need. Make sure to filter the information you need — not everything you will find will be useful for this simple exercise.\n",
"\n",
"What is the correct ``my_complex_number`` variable?\n",
"\n",
"* my_complex_number = 3 + 2i
\n",
"* my_complex_number = 3 + 2j
\n",
"* my_complex_number = 3 + 2k
\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "6acdf92e",
"metadata": {
"tags": [
"remove-input"
]
},
"outputs": [
{
"data": {
"text/html": [
"my_complex_number
variable?\", \"type\": \"many_choice\", \"answers\": [{\"answer\": \"my_complex_number = 3 + 2i
\", \"correct\": false, \"feedback\": \"I hope not.\"}, {\"answer\": \"my_complex_number = 3 + 2j
\", \"correct\": true, \"feedback\": \"Correct.\"}, {\"answer\": \"my_complex_number = 3 + 2k
\", \"correct\": false, \"feedback\": \"I hope not.\"}]}];\n // Make a random ID\nfunction makeid(length) {\n var result = [];\n var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n var charactersLength = characters.length;\n for (var i = 0; i < length; i++) {\n result.push(characters.charAt(Math.floor(Math.random() * charactersLength)));\n }\n return result.join('');\n}\n\n// Choose a random subset of an array. Can also be used to shuffle the array\nfunction getRandomSubarray(arr, size) {\n var shuffled = arr.slice(0), i = arr.length, temp, index;\n while (i--) {\n index = Math.floor((i + 1) * Math.random());\n temp = shuffled[index];\n shuffled[index] = shuffled[i];\n shuffled[i] = temp;\n }\n return shuffled.slice(0, size);\n}\n\nfunction printResponses(responsesContainer) {\n var responses=JSON.parse(responsesContainer.dataset.responses);\n var stringResponses='IMPORTANT!To preserve this answer sequence for submission, when you have finalized your answers: //
and %
operators.\", \"type\": \"many_choice\", \"answers\": [{\"answer\": \"4 pizza slices per engineer and 4 untouched slices.\", \"correct\": false, \"feedback\": \"I hope not.\"}, {\"answer\": \"6.4 pizza slices per engineer and 0 untouched slices. \", \"correct\": false, \"feedback\": \"I hope not.\"}, {\"answer\": \"6 pizza slices per engineer and 2 untouched slices. \", \"correct\": true, \"feedback\": \"Correct.\"}]}];\n // Make a random ID\nfunction makeid(length) {\n var result = [];\n var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n var charactersLength = characters.length;\n for (var i = 0; i < length; i++) {\n result.push(characters.charAt(Math.floor(Math.random() * charactersLength)));\n }\n return result.join('');\n}\n\n// Choose a random subset of an array. Can also be used to shuffle the array\nfunction getRandomSubarray(arr, size) {\n var shuffled = arr.slice(0), i = arr.length, temp, index;\n while (i--) {\n index = Math.floor((i + 1) * Math.random());\n temp = shuffled[index];\n shuffled[index] = shuffled[i];\n shuffled[i] = temp;\n }\n return shuffled.slice(0, size);\n}\n\nfunction printResponses(responsesContainer) {\n var responses=JSON.parse(responsesContainer.dataset.responses);\n var stringResponses='IMPORTANT!To preserve this answer sequence for submission, when you have finalized your answers: