{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "365866b2",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Review of Basic Programming with Python\n",
    "#### CS 66: Introduction to Computer Science II"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8d672df9",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Purpose\n",
    "\n",
    "For those with Python experience: review, make you aware of some things you may not have seen before - it will _not_ be exhaustive.\n",
    "\n",
    "For those without Python experience: introduction to Python syntax\n",
    "* It can do most of what you know from Java, Javascript, etc. \n",
    "* Easy-to-pick-up syntax\n",
    "\n",
    "\n",
    "## References for this lecture\n",
    "\n",
    "Problem Solving with Algorithms and Data Structures using Python, Chapter 1: [https://runestone.academy/runestone/books/published/pythonds/Introduction/toctree.html](https://runestone.academy/runestone/books/published/pythonds/Introduction/toctree.html)\n",
    "\n",
    "Sections 1.1-1.4, 1.7, 1.8, 1.10, 1.12\n",
    "\n",
    "Also see [Think Python](https://greenteapress.com/thinkpython2/html/index.html) for a more exhaustive reference of basic Python or [A Quick Python tutorial](https://www.programiz.com/python-programming/tutorial)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "37434004",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Demo: Running Python\n",
    "\n",
    "Python can be run in either _script mode_ or _interactive mode_\n",
    "\n",
    "My slides are written using a _Jupyter Notebook_ mixes _interactive mode_ cells and mark-up/documentation cells"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3a080cfd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello CS66 Students!\n"
     ]
    }
   ],
   "source": [
    "print(\"Hello CS66 Students!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4db98095",
   "metadata": {},
   "source": [
    "Let's see how _script mode_ and _interactive mode_ works in VSCode"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f81b321d",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Demo: Using a Jupyter Notebook in VS Code\n",
    "\n",
    "If this works, it could be a useful way to work through in-class activities\n",
    "\n",
    "Let's try it."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd0bb20b",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Demo: Submitting assignments on codePost"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c5ed5432",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Objects\n",
    "\n",
    "Python data items are called __objects__.\n",
    "\n",
    "Examples of _types_ of objects\n",
    "* _atomic_ types like ints, floats, and bools\n",
    "* _collection_ types like lists, strings, dictionaries, tuples, and sets\n",
    "* new types created by defining a new class\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "abe900d2",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Examples of numerical and logical operations\n",
    "\n",
    "from Activities 1.8.1.1 and 1.8.1.2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "23c02a56",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "14\n",
      "20\n",
      "1024\n",
      "2.0\n",
      "2.3333333333333335\n",
      "2\n",
      "1\n",
      "0.5\n",
      "0\n",
      "3\n",
      "1267650600228229401496703205376\n"
     ]
    }
   ],
   "source": [
    "print(2+3*4)\n",
    "print((2+3)*4)\n",
    "print(2**10)   ## ** is the exponent operator\n",
    "print(6/3)\n",
    "print(7/3)\n",
    "print(7//3)    ## integer division\n",
    "print(7%3)     ## remainder (modulo)\n",
    "print(3/6)\n",
    "print(3//6)\n",
    "print(3%6)\n",
    "print(2**100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "60e9e0bf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "print(5==10)\n",
    "print(10 > 5)\n",
    "print((5 >= 1) and (5 <= 10))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a8449dac",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Variables\n",
    "\n",
    "Assignments of values to variables in Python is done with the `=` operator\n",
    "\n",
    "variables do not need to be declared ahead of time, and their types can change"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "bcfca474",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'bool'>\n",
      "<class 'int'>\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "x = False\n",
    "print( type(x) )\n",
    "x = 1\n",
    "x = x + 1\n",
    "print( type(x) )\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fc06241f",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Lists\n",
    "\n",
    "Lists are Python's ordered collection type (some other langauges call them _arrays_)\n",
    "\n",
    "They are _heterogeneous_ - they can have a mix of object types."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a9559425",
   "metadata": {},
   "outputs": [],
   "source": [
    "myList = [1,3,True,6.5]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4a600339",
   "metadata": {},
   "source": [
    "Use subscipt notation to access elements by their index. \n",
    "\n",
    "Indices are 0-based"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "0cfe8bfd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6.5\n",
      "['hi', 3, True, 6.5]\n"
     ]
    }
   ],
   "source": [
    "print(myList[3])\n",
    "myList[0] = \"hi\"\n",
    "print(myList)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "48ed7821",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "There are many different built-in functions and methods that work with lists"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7947eed6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1024, 3, True, 6.5, False]\n"
     ]
    }
   ],
   "source": [
    "myList = [1024, 3, True, 6.5]\n",
    "myList.append(False)  #add on to the end of a list\n",
    "print(myList)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8147619a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1024, 3, 4.5, True, 6.5, False]\n"
     ]
    }
   ],
   "source": [
    "myList.insert(2,4.5)  #put a new value at index 2\n",
    "print(myList)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "48e848d8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "[1024, 3, 4.5, True, 6.5]\n"
     ]
    }
   ],
   "source": [
    "print(myList.pop())  #remove and return whatever is at the end\n",
    "print(myList)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "167f0aa9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "[1024, 4.5, True, 6.5]\n",
      "[1024, 4.5, 6.5]\n"
     ]
    }
   ],
   "source": [
    "print(myList.pop(1)) #remove and return whatever is at index 1\n",
    "print(myList)\n",
    "myList.pop(2)\n",
    "print(myList)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "563c6c4a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2.5, 6.63, 10, 47]\n"
     ]
    }
   ],
   "source": [
    "anotherList = [10,2.5,47,1,6.63]\n",
    "anotherList.sort()  #sort the list\n",
    "print(anotherList)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "d3e0d6ba",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[6.63, 1, 47, 2.5, 10]\n"
     ]
    }
   ],
   "source": [
    "anotherList = [10,2.5,47,1,6.63]\n",
    "anotherList.reverse()  #reverse the list\n",
    "print(anotherList)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "2c6eba6f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "anotherList = [10,47,2.5,47,1,6.63,47]\n",
    "print(anotherList.count(47))   #count how many times 47 appears\n",
    "print(anotherList.index(2.5))  #which index is 2.5 at?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "f5b003cb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "print( 42 in anotherList )  #test if 42 is a member of the list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "778f0ab0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[10, 47, 47, 1, 6.63, 47]\n"
     ]
    }
   ],
   "source": [
    "anotherList.remove(2.5)  #remove an item by its value\n",
    "print(anotherList)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "1230e88d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[47, 1]\n"
     ]
    }
   ],
   "source": [
    "#slice the list from index 2 up to (but not including) index 4\n",
    "print( anotherList[2:4] ) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "7ad1da55",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1024, 4.5, 6.5, 10, 47, 47, 1, 6.63, 47]\n"
     ]
    }
   ],
   "source": [
    "print( myList + anotherList ) #concatenate two lists"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "95bd87f9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n"
     ]
    }
   ],
   "source": [
    "print( len(anotherList) )  #find the length of a list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f6204b8",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Strings and Tuples\n",
    "\n",
    "Strings and Tuples behave much like lists, but they're _immutable_ - they can't be changed"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "0d2dce24",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "4.96\n"
     ]
    }
   ],
   "source": [
    "myTuple = (2,True,4.96)\n",
    "print( len(myTuple) )\n",
    "print( myTuple[2] )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "95905d31",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'tuple' object does not support item assignment",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[0;32mIn [20]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mmyTuple\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m10\u001b[39m\n",
      "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
     ]
    }
   ],
   "source": [
    "myTuple[0] = 10 #error because tuples are immutable"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "349af913",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "r\n",
      "eric\n"
     ]
    }
   ],
   "source": [
    "myString = \"Eric\"\n",
    "print( myString[1] )\n",
    "print( myString.lower() )  #there are many useful string methods"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "05bd0579",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## While loops\n",
    "\n",
    "Here's an example of the syntax for a Python `while` loop."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "294e79cf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello, world\n",
      "Hello, world\n",
      "Hello, world\n",
      "Hello, world\n",
      "Hello, world\n"
     ]
    }
   ],
   "source": [
    "counter = 1\n",
    "while counter <= 5:\n",
    "    print(\"Hello, world\")\n",
    "    counter = counter + 1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9f046743",
   "metadata": {},
   "source": [
    "In Python, tabs matter! You always tab in any block of code associated with a loop, if-statement, function definition, etc."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3ca34004",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## For loops\n",
    "\n",
    "`for` loops can be used to iterate through collections\n",
    "\n",
    "In this example, `day` is the _loop variable_ that takes on the next value in the list with each iteration."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "0bf358d8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Sunday is a good day for programming\n",
      "Monday is a good day for programming\n",
      "Tuesday is a good day for programming\n",
      "Wednesday is a good day for programming\n",
      "Thursday is a good day for programming\n",
      "Friday is a good day for programming\n",
      "Saturday is a good day for programming\n"
     ]
    }
   ],
   "source": [
    "days_of_the_week = [\"Sunday\",\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\"]\n",
    "\n",
    "\n",
    "for day in days_of_the_week:\n",
    "    print(day,\"is a good day for programming\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e53e4e30",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## For loops and `range()`\n",
    "\n",
    "For loops are often combined with the `range()` function, which allow it to operate as a count-controlled loop."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "5e23119b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 squared is 0\n",
      "1 squared is 1\n",
      "2 squared is 4\n",
      "3 squared is 9\n",
      "4 squared is 16\n"
     ]
    }
   ],
   "source": [
    "for num in range(5):\n",
    "    print(num,\"squared is\",num**2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7b45cb8a",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "It's also common to use `range()` with `for` loops to iterator through the _indices_ of a list rather than the items of the list."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "ec3588e3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Sunday is a good day for programming\n",
      "Monday is a good day for programming\n",
      "Tuesday is a good day for programming\n",
      "Wednesday is a good day for programming\n",
      "Thursday is a good day for programming\n",
      "Friday is a good day for programming\n",
      "Saturday is a good day for programming\n"
     ]
    }
   ],
   "source": [
    "days_of_the_week = [\"Sunday\",\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\"]\n",
    "\n",
    "\n",
    "for day_num in range(len(days_of_the_week)):\n",
    "    print(days_of_the_week[day_num],\"is a good day for programming\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "48a102a1",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "It's easy to mix up whether you're iterating through _items_ or _indices_, so make sure to think twice about how you're setting up you loops!"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "81e8b657",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Conditional Statements\n",
    "\n",
    "Python has `if`, `else`, and `elif` keywords to handle all of your conditional needs."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "543499d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "students = 124\n",
    "classrooms = 5\n",
    "\n",
    "if classrooms <= 0:\n",
    "    print(\"You must have at least one classroom.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "5eda5d70",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "There are 24.8 students per classroom.\n"
     ]
    }
   ],
   "source": [
    "students = 124\n",
    "classrooms = 5\n",
    "\n",
    "if classrooms <= 0:\n",
    "    print(\"You must have at least one classroom.\")\n",
    "else:\n",
    "    print(\"There are\",students/classrooms,\"students per classroom.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "9e333421",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "C\n"
     ]
    }
   ],
   "source": [
    "score = 76\n",
    "\n",
    "if score >= 90:\n",
    "       print('A')\n",
    "elif score >=80:\n",
    "       print('B')\n",
    "elif score >= 70:\n",
    "       print('C')\n",
    "elif score >= 60:\n",
    "       print('D')\n",
    "else:\n",
    "       print('F')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "296070c1",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Defining Functions\n",
    "\n",
    "You can define functions in Python with the `def` keyword. \n",
    "\n",
    "Parameters are listed as comma,separated variable names between parentheses.\n",
    "\n",
    "The `return` keyword causes the function to terminate, with the given value returned."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "1ead183a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9\n"
     ]
    }
   ],
   "source": [
    "def square(n):\n",
    "    return n**2\n",
    "\n",
    "print( square(3) )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "d2e741b2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "81"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "square( square(3) )"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "445561ef",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## In-Class Activities\n",
    "\n",
    "Make a group of 3-4 students. \n",
    "\n",
    "Have a discussion about each of these problems. Write notes either in this notebook, the comments of a regular Python file, or in some other convenient place.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9b55d464",
   "metadata": {},
   "source": [
    "## Group Activity Problem 1\n",
    "\n",
    "Run the following code example. In the notes section below, describe what the code does."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4df9a297",
   "metadata": {},
   "outputs": [],
   "source": [
    "anotherList = [10,47,2.5,47,1,6.63,47]\n",
    "print(anotherList.index(2.5))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f6f89132",
   "metadata": {},
   "source": [
    "### Notes: \n",
    "\n",
    "_you may use this space for your notes_"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6972da10",
   "metadata": {},
   "source": [
    "## Group Activity Problem 2\n",
    "\n",
    "What happens if you try to use the `index` method for an item that doesn't appear in the list?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c99a2a54",
   "metadata": {},
   "outputs": [],
   "source": [
    "## test some code here"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c803a2d9",
   "metadata": {},
   "source": [
    "### Notes: \n",
    "\n",
    "_write your notes here_"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "82a31f51",
   "metadata": {},
   "source": [
    "## Group Activity Problem 3\n",
    "\n",
    "How is the list `index` method different than the `in` operator?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b843c42e",
   "metadata": {},
   "outputs": [],
   "source": [
    "my_list = [35,66,70,5,42,10,12]\n",
    "print(42 in my_list)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0f792471",
   "metadata": {},
   "source": [
    "### Notes: \n",
    "\n",
    "_write your notes here_"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "abaf9e25",
   "metadata": {},
   "source": [
    "## Group Activity Problem 4\n",
    "\n",
    "In the previous activity, you wrote a `search_for` function which served the same purpose as the `in` (e.g., list-contains) operator. Now write a similar function called `find_index` which serves the same purpose as the list `index` method you worked with above. However, instead of giving an error when the item isn't in the list, return -1 instead. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "42b183e0",
   "metadata": {},
   "outputs": [],
   "source": [
    "# write your code here"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f0a1d426",
   "metadata": {},
   "source": [
    "### Notes: \n",
    "\n",
    "_write your notes here_"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9946c40a",
   "metadata": {},
   "source": [
    "## Group Activity Problem 5\n",
    "\n",
    "Write a function called `find_index_2D()` that will find the position of an item in a 2-dimension list. For example, if called like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "759a234c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# write your code here\n",
    "\n",
    "my_2d_list = [[0,1,2,3],\n",
    "              [10,11,12,13],\n",
    "              [20,21,22,23]]\n",
    "\n",
    "print( find_index_2D(12,my_2d_list) ) #it should return the tuple (1,2) to indicate it is in row 1, column 2."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "18f6dc62",
   "metadata": {},
   "source": [
    "### Notes: \n",
    "\n",
    "_write your notes here_"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Slideshow",
  "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.10.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
