{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Important reminder\n",
    "\n",
    "No lecture on 1 Nov. 2024 due to holiday.\n",
    "\n",
    "Lecture will be at start of tutorial on 4 Nov. 2024 (at the normal tutorial time and loaction, namely 14:15 in the Computer Pool in Bio 2/3 building.)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "feb8c8c062f27870a881fb5cdec17288",
     "grade": false,
     "grade_id": "cell-e925a1ea56688b2e",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "# types, variables, assignment, indexing, slicing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "a6818b1513f33a9fe0bf7acfccae05b0",
     "grade": false,
     "grade_id": "cell-e21110f11e6d841a",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# You must run this cell, but you can ignore its contents.\n",
    "\n",
    "import hashlib\n",
    "\n",
    "def ads_hash(ty):\n",
    "    \"\"\"Return a unique string for input\"\"\"\n",
    "    ty_str = str(ty).encode()\n",
    "    m = hashlib.sha256()\n",
    "    m.update(ty_str)\n",
    "    return m.hexdigest()[:10]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "3c4eb0b89407c062482c58173f398142",
     "grade": false,
     "grade_id": "cell-179bf0a88bde01d6",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "# Types\n",
    "\n",
    "Please answer the questions about Python types. Here we will use the spelling that Python uses for the types. Thus, we write `int` (not e.g. `integer`) and `str` (not e.g. `string`)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "48a5a741a9171f0c44ea7d44002f9a91",
     "grade": false,
     "grade_id": "cell-dffd2c4d1820c148",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q1\n",
    "\n",
    "What is the type of the following:\n",
    "\n",
    "`10`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "b8237ddca4ebd3337ce49aa01dc7b16f",
     "grade": false,
     "grade_id": "cell-4c5bb2e24cd0b4b8",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "66e6386e4d530c75372efb17fcda7780",
     "grade": true,
     "grade_id": "cell-a534d123d26a6e42",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# If this runs without error, it means the answer in your previous cell was correct.\n",
    "assert ads_hash(_)=='f918a1a5ca'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "d9a1a48e57dc65debb3e4fdd14f2e7ea",
     "grade": false,
     "grade_id": "cell-02ed8f0df4c12fe7",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q2\n",
    "\n",
    "What is the type of the following:\n",
    "    \n",
    "`[1,2,3,4]`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "78cbd736a36839043363d6f4f20e629a",
     "grade": false,
     "grade_id": "cell-c53f7736f3ef6a4d",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "58d36d5b50fcc55ae9793388331fe6b2",
     "grade": true,
     "grade_id": "cell-0997a02809ef51df",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# If this runs without error, it means the answer in your previous cell was correct.\n",
    "assert ads_hash(_)=='981a391f15'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "cd1d7f6a91a6017d169f52de77e7da4a",
     "grade": false,
     "grade_id": "cell-df6875a7f373d1e8",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q3\n",
    "\n",
    "What is the type of the following:\n",
    "    \n",
    "`(1,2,3,4)`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "cd37b73cd9e4f9332765c8e7258c9f8e",
     "grade": false,
     "grade_id": "cell-cecba2dc8f2a1fcb",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "e0e760c595472d2219d694bcbbbfaf20",
     "grade": true,
     "grade_id": "cell-d8e48e520e48ecbb",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# If this runs without error, it means the answer in your previous cell was correct.\n",
    "assert ads_hash(_)=='99e8d934d2'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Q4\n",
    "\n",
    "What is the type of the following:\n",
    "    \n",
    "`\"(1,2,3,4)\"`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "f9bb56f698045ee96f62056b9a84b3f7",
     "grade": false,
     "grade_id": "cell-01390d1edcadb200",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "b5de9ccebef40c9cb43b6c9ce5d329dd",
     "grade": true,
     "grade_id": "cell-81637082eb179284",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# If this runs without error, it means the answer in your previous cell was correct.\n",
    "assert ads_hash(_)=='17a0b2d655'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "2899094c16427790c9daf360a52a3b32",
     "grade": false,
     "grade_id": "cell-3e29ab113c157d73",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q5\n",
    "\n",
    "What is the type of the following:\n",
    "    \n",
    "`'(1,2,3,4)'`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "88eabadf08779cc33162f0ad2ae7380c",
     "grade": false,
     "grade_id": "cell-d6436534e3fbc839",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "a45d9fc86ee9ed5587b243bff8d2b15a",
     "grade": true,
     "grade_id": "cell-0e5bfe7fc5f7997b",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# If this runs without error, it means the answer in your previous cell was correct.\n",
    "assert ads_hash(_)=='17a0b2d655'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "b45ac0e251ddf66b25e9d00281273e1d",
     "grade": false,
     "grade_id": "cell-2e6d7d11312ed89d",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "# Variables and assignment\n",
    "\n",
    "The first questions are a review."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "e00346d2e1ce1e18a61b6909cd2ac3c8",
     "grade": false,
     "grade_id": "cell-803f832c65529b6d",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q1\n",
    "\n",
    "Consider the following code. After this has run, what will the value of `x` be?\n",
    "\n",
    "    x = 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "44799b1ef90e8d95dbc6391bd0d7546f",
     "grade": false,
     "grade_id": "cell-9de8d3cdd252995f",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "19547368c449276ee343818d3f43e68c",
     "grade": true,
     "grade_id": "cell-1ff60a7adb65c261",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# If this runs without error, it means the answer in your previous cell was correct.\n",
    "assert ads_hash(_)=='4a44dc1536'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "bc679f880224df909a7e7e952286d83d",
     "grade": false,
     "grade_id": "cell-fc696d04bf395ee4",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q2\n",
    "\n",
    "Consider the following code. After this has run, what will the value of `x` be?\n",
    "\n",
    "    x = 10\n",
    "    x = x+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "e39267fe03ebd3c0e9b7a85c37ee50f9",
     "grade": false,
     "grade_id": "cell-dae207003862512c",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "0f3984d6dd481ac7018b450ae0e345e3",
     "grade": true,
     "grade_id": "cell-417322b120e1eab7",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# If this runs without error, it means the answer in your previous cell was correct.\n",
    "assert ads_hash(_)=='4fc82b26ae'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "a14a0a36e0544192718b8f20da77a18b",
     "grade": false,
     "grade_id": "cell-91ffd31eabd4a539",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q3\n",
    "\n",
    "Consider the following code. After this has run, what will the value of `x` be?\n",
    "\n",
    "    y = [1,2,3]\n",
    "    x = y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "c92296150d5cf2e64d0fe72db346de62",
     "grade": false,
     "grade_id": "cell-bb17fad77ab0be6f",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "1c3e5190f8bd8d9198cda5b87f814ab4",
     "grade": true,
     "grade_id": "cell-a58b1d4c175e7894",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# If this runs without error, it means the answer in your previous cell was correct.\n",
    "assert ads_hash(_)=='a36b1f2c3f'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "aba535c18d1264af8719d9e11fc2518f",
     "grade": false,
     "grade_id": "cell-1ebdb5ef57dfd542",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "# Indexing"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "7f2fe089ef50c76e87b5f911df7da29a",
     "grade": false,
     "grade_id": "cell-4c3dd2ac7883f171",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q1\n",
    "\n",
    "Consider the following code. After this has run, what will the value of `x` be?\n",
    "\n",
    "    y = [1,2,3]\n",
    "    x = y[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "175814371e7322889952dfc6904187e6",
     "grade": false,
     "grade_id": "cell-f5a2887e76c4321e",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "34cc21ea4ff0df098ad2bec6df9b13f5",
     "grade": true,
     "grade_id": "cell-5314eae929078d10",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# If this runs without error, it means the answer in your previous cell was correct.\n",
    "assert ads_hash(_)=='d4735e3a26'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "58cf86728d4adbe5020a5fe976e81b65",
     "grade": false,
     "grade_id": "cell-11f65d7c9b65371b",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q2\n",
    "\n",
    "Consider the following code. After this has run, what will the value of `x` be?\n",
    "\n",
    "    x = [1,2,3]\n",
    "    x[2] = 42"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "f139a052b3f098f1d0156ab114d703f5",
     "grade": false,
     "grade_id": "cell-8f0317f086f58de7",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "216d2445cb7c828666896761333e5465",
     "grade": true,
     "grade_id": "cell-5aa9f92a6e6efaa0",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# If this runs without error, it means the answer in your previous cell was correct.\n",
    "assert ads_hash(_)=='ac009e066e'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "66636bf3472db3baf12e1f9bc7512aea",
     "grade": false,
     "grade_id": "cell-31c1a47f78680df7",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q3\n",
    "\n",
    "Consider the following code. After this has run, what will the value of `x` be?\n",
    "\n",
    "    x = [1,2,3]\n",
    "    y = x\n",
    "    y[1] = 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "238c7d8db5d4a2a199515b7a5faee658",
     "grade": false,
     "grade_id": "cell-196bc244f1c8042b",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "6c3edbd2028a82bcfa73d8a0625e79db",
     "grade": true,
     "grade_id": "cell-39cc1a93f8204257",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# If this runs without error, it means the answer in your previous cell was correct.\n",
    "assert ads_hash(_)=='26796b1e40'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "4cc685a56340263df3a497af57aac484",
     "grade": false,
     "grade_id": "cell-bc63d89f8ac73cc7",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "# Slicing"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "adf8c69797ba236557a2c1caab99126f",
     "grade": false,
     "grade_id": "cell-59f33c7f581a643f",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q1\n",
    "\n",
    "Consider the following code. After this has run, what will the value of `x` be?\n",
    "\n",
    "    y = [1,2,3,4,5]\n",
    "    x = y[1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "f637ef67986b4c900b85878ca71dff87",
     "grade": false,
     "grade_id": "cell-c5984871c943365a",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "30a6d2636e3009ee916c72bf53ba99c0",
     "grade": true,
     "grade_id": "cell-f9f8e930e5642969",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# If this runs without error, it means the answer in your previous cell was correct.\n",
    "assert ads_hash(_)=='5bf775530e'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "3824757d1efe646786fdbcb3fab945cd",
     "grade": false,
     "grade_id": "cell-5b06ff43b2d2b492",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q2\n",
    "\n",
    "Consider the following code. After this has run, what will the value of `x` be?\n",
    "\n",
    "    y = [1,2,3,4,5]\n",
    "    x = y[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "9f23111daf3786ae73f6f884c2093aa0",
     "grade": false,
     "grade_id": "cell-7f8aa29eb2af0b7f",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "faed0fcdbd0a9969af2a81f71c9d6433",
     "grade": true,
     "grade_id": "cell-b9af5eba45805af2",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# If this runs without error, it means the answer in your previous cell was correct.\n",
    "assert ads_hash(_)=='a36b1f2c3f'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "74b1a1de3e27851bd96443dd1ea6efe6",
     "grade": false,
     "grade_id": "cell-bcddf90d39f648f9",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q3\n",
    "\n",
    "Consider the following code. After this has run, what will the value of `x` be?\n",
    "\n",
    "    y = [1,2,3,4,5]\n",
    "    x = y[-4:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "339cf09c7cb0bff2e0d84ccaf6e564e0",
     "grade": false,
     "grade_id": "cell-c921dc35e4b5e16e",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "d324a0c495111d640a651b4e4833897c",
     "grade": true,
     "grade_id": "cell-1ba38ad0ab22e86e",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# If this runs without error, it means the answer in your previous cell was correct.\n",
    "assert ads_hash(_)=='c4204dd36f'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "63ad92efcf89f078dbfc5f308afa6c80",
     "grade": false,
     "grade_id": "cell-ad8a134c4668a0d6",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "# Functions\n",
    "\n",
    "Theses questions should be a review for you"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "82ef4189cb805280307ed66360f94e66",
     "grade": false,
     "grade_id": "cell-45775cc0e99b3744",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q1\n",
    "\n",
    "Define a function called `my_function` which returns its input multiplied by three."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "66a514c5f1ae96eafe57e9dcb28a0fbe",
     "grade": false,
     "grade_id": "cell-450afdf17d3b0b19",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "dc62aeff00921ed8c919316322b0130d",
     "grade": true,
     "grade_id": "cell-22f30ed9a48dc320",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# If this runs without error, it means `my_function` does indeed return three times its input.\n",
    "assert my_function(0)==0\n",
    "assert my_function(1)==3\n",
    "assert my_function(100)==300"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "85f2a1f575a1360d2faa9f990f3540a5",
     "grade": false,
     "grade_id": "cell-2ecaa6ef333bc779",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q2\n",
    "\n",
    "Here is a function definition for `a_times_b`, but this code has a problem. Fix the problem by defining a function `a_times_b` so that the tests below pass.\n",
    "\n",
    "```\n",
    "def a_times_b(a,b):\n",
    "    a*b\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "7bfdadbc00c1d0849db85edf9fbe0f4f",
     "grade": false,
     "grade_id": "cell-7d6d492c969fd4cc",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "e089d5458ebc28b7a2d90070d3e5725c",
     "grade": true,
     "grade_id": "cell-739d96807909739e",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# If this runs without error, it means `a_times_b` does indeed function as expected.\n",
    "assert a_times_b(0,10)==0\n",
    "assert a_times_b(10,10)==100\n",
    "assert a_times_b(10,0)==0\n",
    "assert a_times_b(6,7)==42\n",
    "assert a_times_b(7,6)==42"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "e55cc26c2db56cfb8863ec4faa5a18f2",
     "grade": false,
     "grade_id": "cell-c61877577f449834",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q3\n",
    "\n",
    "Make a function named `append3` which assumes its input argument is a `list` and appends the number `3` to it. Your function should return `None`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "faa15ec47d0dbfe8cd1b715c63e96be0",
     "grade": false,
     "grade_id": "cell-af763dc40964a8bd",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "127217d692d06f3e6fef1226d7f5f0a8",
     "grade": true,
     "grade_id": "cell-dfe77036dc289698",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "x = [1,4,10]\n",
    "assert ads_hash(append3(x))=='dc937b5989'\n",
    "assert ads_hash(x)=='c2a0352fa1'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "b85de81bede4e1c22e34eba4fa9e834f",
     "grade": false,
     "grade_id": "cell-2a1fc2dc6eef9997",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "# Plotting"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "51f1e89b4312ff4265dd78ab7f264715",
     "grade": false,
     "grade_id": "cell-dd7086db2c448b9f",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# Below, we will use matplotlib, so we need to import it here.\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "fb0499452cf4db190f987edc9e3ec906",
     "grade": false,
     "grade_id": "cell-44b659b622ef1e36",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q1\n",
    "\n",
    "Given the following data, make a plot that looks like this:\n",
    "\n",
    "```\n",
    "x=[1,2,3,4,5,6,7,8,9,10]\n",
    "y=[0,4,0,3,3,0,3,4,5,2]\n",
    "```\n",
    "\n",
    "<img src=\"data:image/png;base64,[encoded data, 16568 characters]\" alt=\"\" />"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "047c25ed895fced570c5642809361705",
     "grade": true,
     "grade_id": "cell-4283e6e240253fb1",
     "locked": false,
     "points": 1,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "9cb93b43a6268b51c0648b620f9dce0f",
     "grade": false,
     "grade_id": "cell-0fbdb51502e1211a",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q2\n",
    "\n",
    "Given the following data, make a plot that looks like this:\n",
    "\n",
    "```\n",
    "x=[1,2,3,4,5,6,7,8,9,10]\n",
    "y1=[0,4,0,3,3,0,3,4,5,2]\n",
    "y2=[3,2,4,4,2,4,4,2,4,2]\n",
    "```\n",
    "\n",
    "Hint, you can draw two lines by making two calls to `plt.plot()`.\n",
    "\n",
    "<img src=\"data:image/png;base64,[encoded data, 23804 characters]\" alt=\"\" />"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "f9a19bf9b59df7b822bc0c028fcde474",
     "grade": true,
     "grade_id": "cell-84eca66f88093703",
     "locked": false,
     "points": 1,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "ca22d24fb5378eed07a485eb88b1867e",
     "grade": false,
     "grade_id": "cell-911d3f2c6efedebc",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "# Scopes\n",
    "\n",
    "## Q1\n",
    "\n",
    "Fix the following code so that `myfunc` returns its input argument times `34`.\n",
    "\n",
    "```python\n",
    "x = 100\n",
    "\n",
    "def myfunc(a):\n",
    "    return x*34\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "83bff64fd492c8387adc6eae81d0c99a",
     "grade": false,
     "grade_id": "cell-e62ac462a1466c64",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "86606dcc3536ef0bf3ca87b8e2b30944",
     "grade": true,
     "grade_id": "cell-66f596032f6fb1ae",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "assert ads_hash(myfunc(12))=='e6f47e008c'\n",
    "assert ads_hash(myfunc(123))=='ecdf40652a'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "3e262069088d60ce5f55a1d10918be1c",
     "grade": false,
     "grade_id": "cell-9f94cfbb2410ebbe",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q2\n",
    "\n",
    "Modify the definition of the `func1` function so that it returns its input argument times `y` from the global scope. Keep the `y = 123` in your answer cell, but not in your function.\n",
    "\n",
    "```python\n",
    "y = 123\n",
    "\n",
    "def func1(x):\n",
    "    x*2\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "c50c6d25bc200c9f85f84a036598c36d",
     "grade": false,
     "grade_id": "cell-f052e86277ac2b09",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "a3761860c61b2923e822b9e088d7a6b2",
     "grade": true,
     "grade_id": "cell-b6a2675dfc4862ea",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "assert ads_hash(func1(4))=='23e8b01758'\n",
    "assert ads_hash(func1(10))=='22a2fa7d04'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "5424d6b42d0093782e844bd584bc31f2",
     "grade": false,
     "grade_id": "cell-d92472e0e9ea07f6",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q3 - Mixed function return values and \"side effects\"\n",
    "\n",
    "Consider this function:\n",
    "\n",
    "```python\n",
    "a = []\n",
    "def find_num(x,a):\n",
    "    a.append(x)\n",
    "    if x > 10:\n",
    "        return x/2\n",
    "    else:\n",
    "        return find_num(x+2,a)\n",
    "```\n",
    "\n",
    "Notice that each time the function runs, `a` in the global scope will get the value of `x` appended to it.\n",
    "\n",
    "How many times does this function run when started with `x=2`? Hint: you can check the length of the list `a` after it finishes running. To get the length of a list named `a`, use `len(a)`.\n",
    "\n",
    "Put your answer in the variable `n_runs`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "9f76aa4d69e4c174f50af0351aeab5af",
     "grade": false,
     "grade_id": "cell-13834aebe49a3a45",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "a94d309cccd04ed16d5f426a4222bdd6",
     "grade": true,
     "grade_id": "cell-e350e97fb2289044",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "assert ads_hash(n_runs)=='e7f6c01177'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "848f8a5e0035e69950ac81788628ba7a",
     "grade": false,
     "grade_id": "cell-7d69975a16852789",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "# Fibonacci\n",
    "\n",
    "You may know the [Fibonacci sequence](https://en.wikipedia.org/wiki/Fibonacci_number).\n",
    "\n",
    "```\n",
    "0 1 1 2 3 5 8 13\n",
    "```\n",
    "\n",
    "Notice that, after the first two numbers, each number is the sum of the previous two.\n",
    "\n",
    "Let's make a Python program to generate it!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "a14b6c5fee6da74a0645c71bef10aa8a",
     "grade": false,
     "grade_id": "cell-a797acc2cd4e44c3",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "def exten_fib(a):\n",
    "    if len(a) < 2:\n",
    "        raise ValueError(\"not enough entries\")\n",
    "    num1 = a[-2]\n",
    "    num2 = a[-1]\n",
    "    a.append(num1+num2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "8882da877fb700c238229e815a5e1b56",
     "grade": false,
     "grade_id": "cell-2042696ad549c125",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "a=[0,1]\n",
    "exten_fib(a)\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Modify this cell to explore calling `exten_fib` many times.\n",
    "\n",
    "a=[0,1]\n",
    "exten_fib(a)\n",
    "exten_fib(a)\n",
    "exten_fib(a)\n",
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "markdown",
     "checksum": "6228ad7111f31de2b49bfe0e59b8ecb1",
     "grade": false,
     "grade_id": "cell-5770be94eba1bc42",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Q1\n",
    "\n",
    "What is the next Fibonacci number after 987? Put your answer in the variable `after987`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "67ec330ce05e67951769c6c089e2c45c",
     "grade": false,
     "grade_id": "cell-e7674742e304e19f",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# YOUR CODE HERE\n",
    "raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "270e0b3fcbbf7cb5723cfcdc53dc8a90",
     "grade": true,
     "grade_id": "cell-0f5d26430311d09e",
     "locked": true,
     "points": 1,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "assert ads_hash(after987)=='eb57f94995'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
