Some improvements in the first notebooks

This commit is contained in:
Francesc Verdugo
2024-08-19 15:58:09 +02:00
parent 047d6feadb
commit 5abdc088d2
5 changed files with 307 additions and 203 deletions

View File

@@ -147,6 +147,44 @@
"foo()"
]
},
{
"cell_type": "markdown",
"id": "d18e679d",
"metadata": {},
"source": [
"### A very easy first exercise\n",
"\n",
"Run the following cell. It contains definitions used later in the notebook."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "81678b3d",
"metadata": {},
"outputs": [],
"source": [
"function why_q1()\n",
" msg = \"\"\"\n",
" In the first line, we assign a variable to a value. In the second line, we assign another variable to the same value. Thus, we have 2 variables associated with the same value. In line 3, we associate y to a new value (re-assignment). Thus, we have 2 variables associated with 2 different values. Variable x is still associated with its original value. Thus, the value at the final line is x=1.\n",
" \"\"\"\n",
" println(msg)\n",
"end\n",
"function why_q2()\n",
" msg = \"\"\"\n",
" It will be 1 for very similar reasons as in the previous questions: we are reassigning a local variable, not the global variable defined outside the function.\n",
" \"\"\"\n",
" println(msg)\n",
"end\n",
"function why_q3()\n",
" msg = \"\"\"\n",
" It will be 6. In the returned function f2, x is equal to 2. Thus, when calling f2(3) we compute 2*3.\n",
" \"\"\"\n",
" println(msg)\n",
"end\n",
"println(\"🥳 Well done! \")"
]
},
{
"cell_type": "markdown",
"id": "92112bd1",
@@ -467,6 +505,24 @@
"x"
]
},
{
"cell_type": "markdown",
"id": "a2f94960",
"metadata": {},
"source": [
"Run next cell to get an explanation of this question."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fc562337",
"metadata": {},
"outputs": [],
"source": [
"why_q1()"
]
},
{
"cell_type": "markdown",
"id": "4d2cb752",
@@ -586,6 +642,24 @@
"x"
]
},
{
"cell_type": "markdown",
"id": "f69108c2",
"metadata": {},
"source": [
"Run next cell to get an explanation of this question."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "05c62aa3",
"metadata": {},
"outputs": [],
"source": [
"why_q2()"
]
},
{
"cell_type": "markdown",
"id": "4fc5eb9b",
@@ -1068,6 +1142,24 @@
"x"
]
},
{
"cell_type": "markdown",
"id": "062ff145",
"metadata": {},
"source": [
"Run next cell to get an explanation of this question."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6bf7818e",
"metadata": {},
"outputs": [],
"source": [
"why_q3()"
]
},
{
"cell_type": "markdown",
"id": "bc8e9bcf",
@@ -1257,16 +1349,6 @@
"squares[2:3] = [4,9]"
]
},
{
"cell_type": "markdown",
"id": "92248ad5",
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-info\">\n",
"<b>Tip:</b> Note that Julia array indexing is 1-based (like in Fortran, but unlike C,C++,Python). Love it or hate it. 🙂\n",
"</div>"
]
},
{
"cell_type": "markdown",
"id": "f64021ab",