From a4ea8b7de74f9612310f71546722948838038f2c Mon Sep 17 00:00:00 2001
From: Louis Oliphant <ltoliphant@wisc.edu>
Date: Fri, 6 Sep 2024 09:20:47 -0500
Subject: [PATCH] still working on lec 3 operators

---
 .../Lec_03_Operators_Template_Oliphant.ipynb  | 155 +++++++++++++++++-
 1 file changed, 147 insertions(+), 8 deletions(-)

diff --git a/f24/Louis_Lecture_Notes/03_Operators/Lec_03_Operators_Template_Oliphant.ipynb b/f24/Louis_Lecture_Notes/03_Operators/Lec_03_Operators_Template_Oliphant.ipynb
index 52af0e6..2bbbf8e 100644
--- a/f24/Louis_Lecture_Notes/03_Operators/Lec_03_Operators_Template_Oliphant.ipynb
+++ b/f24/Louis_Lecture_Notes/03_Operators/Lec_03_Operators_Template_Oliphant.ipynb
@@ -27,6 +27,7 @@
     "    - Data Types\n",
     "    - Expressions and operators\n",
     "    - Comments\n",
+    "- Read and understand Python error messages\n",
     "- Use [**Jupyter Lab**](https://jupyterlab.readthedocs.io/en/latest/user/index.html) Features:\n",
     "    - Left-edge side bar\n",
     "    - Notebook menubar\n",
@@ -137,7 +138,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 31,
+   "execution_count": 32,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -174,11 +175,11 @@
     "An **expression** combines values together using **operators** to create a new value.  Each of the following lines of code are examples of expressions.  Try typing them in the cell below and see what new value is created.\n",
     "\n",
     "```python\n",
-    "5-2*3.0\n",
+    "5 - 2 * 3.0\n",
     "\n",
-    "\"Hello\"+\"goodbye\"\n",
+    "4 * \"Hello\"\n",
     "\n",
-    "not True\n",
+    "not True or False\n",
     "```"
    ]
   },
@@ -195,16 +196,154 @@
    "cell_type": "markdown",
    "metadata": {},
    "source": [
-    "It is important that you know the various operators and how they are used with different data types\n",
+    "It is important that you know the various operators and how they are used to combine different data types\n",
+    "\n",
+    "### Mathematical Operators `+` `-` `*` `/` `//` `%` `**`\n",
+    "\n",
+    "You are probably already familiar with `+` (add), `-` (subtract), `*` (multiply), and `/` (float division).  There is a second type of division, `//` (floor division), which truncates the result.  Run each of the following expressions to understand the difference between these two types of division.  **Pay particular attention to the value and the data type of the answer.**  Remember that if you are unsure what the data type is then you can surround the expression with the function `type()`.\n",
+    "\n",
+    "```python\n",
+    "4 / 2\n",
+    "\n",
+    "5 / 2\n",
+    "\n",
+    "4 // 2\n",
+    "\n",
+    "5 // 2\n",
+    "\n",
+    "4.0 / 2\n",
+    "\n",
+    "4.0 // 2\n",
+    "\n",
+    "5.0 / 2\n",
+    "\n",
+    "5.0 // 2\n",
+    "\n",
+    "```"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 35,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "#TODO -- Enter your code here\n"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "The next operator, `%` (modulus or modulo), returns the remainder from a division operation.  Try the following to understand this operator:\n",
+    "\n",
+    "```python\n",
+    "4 % 3\n",
     "\n",
-    "### Mathematical Operators `+` `-` `*` `/` `//` `**` `%`"
+    "5 % 3\n",
+    "\n",
+    "6.1 % 3\n",
+    "```"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 13,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "#TODO -- Enter your code here\n"
    ]
   },
   {
    "cell_type": "markdown",
    "metadata": {},
    "source": [
-    "### String Operators `+` `*`"
+    "The modulus operator is very useful in programming.  Think about the operator and see if you can answer the following questions:\n",
+    "\n",
+    "1. What is the largest value of the expression `M % 4` for any value of M?\n",
+    "\n",
+    "2. What is the smallest value of the expression `M % 4` for any value of M?\n",
+    "\n",
+    "3. What are the different values of an expression `M % 2` if M is even?  if M is odd?\n",
+    "\n",
+    "4. What does modding by 10 tell you about the original number (e.g. `745 % 10`)?\n",
+    "\n",
+    "Also, you can create expressions using the mod operator (`%`) with the floor division operator (`//`) to perform some very useful calculations.  Here is one:  think about each of the following expressions and see if you can understand the usefulness of the expressions?\n",
+    "\n",
+    "```python\n",
+    "\n",
+    "2376 % 10\n",
+    "\n",
+    "(2376 // 10) % 10\n",
+    "\n",
+    "(2376 // 100) % 10\n",
+    "\n",
+    "```\n",
+    "\n",
+    "Use the cell below to help while you are thinking."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 19,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "#TODO -- Enter your code here\n"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "### String Operators `+` `*`\n",
+    "\n",
+    "Run the code below to understand the `+` (concatination) and `*` (replication) string operators.\n",
+    "\n",
+    "```python\n",
+    "\"hello\" + 'goodbye'\n",
+    "\n",
+    "'3' + '4'\n",
+    "\n",
+    "10 * 'X'\n",
+    "```"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 39,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "#TODO -- Enter your code here\n"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "Notice that the plus symbol `+` has multiple meanings in Python.  If the two operands are strings then concatination is performed.  If the two arguments are numbers then addition is performed.  Also notice that the astrisk symbol `*` has multiple meanings.  What happens if you try different types of values with these symbols?  Try running the following and see what happens:\n",
+    "\n",
+    "```python\n",
+    "\n",
+    "3 + 'aloha'\n",
+    "\n",
+    "'X' * '10'\n",
+    "\n",
+    "True + False\n",
+    "\n",
+    "False * 7\n",
+    "```"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 48,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "#TODO -- Enter your code here\n"
    ]
   },
   {
@@ -1050,7 +1189,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.10.12"
+   "version": "3.10.6"
   }
  },
  "nbformat": 4,
-- 
GitLab