diff --git a/README.md b/README.md
index 56f0082..7349954 100644
--- a/README.md
+++ b/README.md
@@ -4,79 +4,78 @@ This is a collection of Jupyter Notebooks for teaching Python programming with a
## Topics
-1. Introduction
- * Using Jupyter notebooks
- * Your First Python Program
+1. Introduction
+ * Using Jupyter notebooks
+ * Your First Python Program
-2. Basic operations
- * Variables, Assignment Statements, Expressions
- * Reading console input
- * Numeric Data Types
- * Operator Precedence
- * Strings
- * Type Conversions
+2. Basic operations
+ * Variables, Assignment Statements, Expressions
+ * Reading console input
+ * Numeric Data Types
+ * Operator Precedence
+ * Strings
+ * Type Conversions
-3. Built-in Functions and Objects
- * Common Functions
- * Objects and Methods
- * Formatting output with `.format()`
+3. Built-in Functions and Objects
+ * Common Functions
+ * Objects and Methods
+ * Formatting output with `.format()`
-4. Branch Logic
- * Boolean Data Types
- * `if` Statements
- * `if` - `else` Statements
- * `if` - `elif` - `else` Statements
- * Logical operators (`and`, `or`, `not`)
- * Operator Precedence
+4. Branch Logic
+ * Boolean Data Types
+ * `if` Statements
+ * `if` - `else` Statements
+ * `if` - `elif` - `else` Statements
+ * Logical operators (`and`, `or`, `not`)
+ * Operator Precedence
-5. Iteration (Loops)
- * `for` Loop
- * `while` Loop
- * Nested Loops
- * `break` and `continue`
+5. Iteration (Loops)
+ * `for` Loop
+ * `while` Loop
+ * Nested Loops
+ * `break` and `continue`
-6. User Defined Functions
- * Introduction
- * Defining Functions
- * Calling Functions
- * Arguments and Parameters
- * Variable Scope
+6. User Defined Functions
+ * Introduction
+ * Defining Functions
+ * Calling Functions
+ * Arguments and Parameters
+ * Variable Scope
-7. Collections: Lists, Dictionaries, Sets, Tuples
- * Creating
- * Accessing Data
- * Functions - Returning Multiple Values
- * Functions - Pass by Value; Pass by Reference
+7. Collections: Lists, Dictionaries, Sets, Tuples
+ * Creating
+ * Accessing Data
+ * Functions - Returning Multiple Values
+ * Functions - Pass by Value; Pass by Reference
-8. File I/O
- * Modes: read (`'r'`), write (`'w'`), append(`'a'`)
- * Ways to Read: `read()`, `readline()`, `readlines()`
- * Writing and Closing: `write()`, `close()`
+8. File I/O
+ * Modes: read (`'r'`), write (`'w'`), append(`'a'`)
+ * Ways to Read: `read()`, `readline()`, `readlines()`
+ * Writing and Closing: `write()`, `close()`
-9. Hashing
- * Hashing Strings
+9. Hashing
+ * Hashing Strings
-10. Exception Handling
- * Catching exceptions
- * Raising exceptions
-
-
-11. Recursion
- * Introduction
- * Examples
+10. Exception Handling
+ * Catching exceptions
+ * Raising exceptions
+
+11. Recursion
+ * Introduction
+ * Examples
-12. OOP
- * User-defined Classes
+12. OOP
+ * User-defined Classes
-13. Misc Topics
+13. Misc Topics
diff --git a/content/00_tableOfContents.ipynb b/content/00_tableOfContents.ipynb
index 0b5fbbe..006d585 100644
--- a/content/00_tableOfContents.ipynb
+++ b/content/00_tableOfContents.ipynb
@@ -10,82 +10,81 @@
"\n",
"## Topics\n",
"\n",
- "1. Introduction\n",
- " * Using Jupyter notebooks\n",
- " * Your First Python Program\n",
+ "1. Introduction\n",
+ " * Using Jupyter notebooks\n",
+ " * Your First Python Program\n",
" \n",
" \n",
- "2. Basic operations\n",
- " * Variables, Assignment Statements, Expressions\n",
- " * Reading console input\n",
- " * Numeric Data Types\n",
- " * Operator Precedence\n",
- " * Strings\n",
- " * Type Conversions\n",
+ "2. Basic operations\n",
+ " * Variables, Assignment Statements, Expressions\n",
+ " * Reading console input\n",
+ " * Numeric Data Types\n",
+ " * Operator Precedence\n",
+ " * Strings\n",
+ " * Type Conversions\n",
" \n",
" \n",
- "3. Built-in Functions and Objects\n",
- " * Common Functions\n",
- " * Objects and Methods\n",
- " * Formatting output with `.format()`\n",
+ "3. Built-in Functions and Objects\n",
+ " * Common Functions\n",
+ " * Objects and Methods\n",
+ " * Formatting output with `.format()`\n",
" \n",
" \n",
- "4. Branch Logic\n",
- " * Boolean Data Types\n",
- " * `if` Statements\n",
- " * `if` - `else` Statements\n",
- " * `if` - `elif` - `else` Statements\n",
- " * Logical operators (`and`, `or`, `not`)\n",
- " * Operator Precedence\n",
+ "4. Branch Logic\n",
+ " * Boolean Data Types\n",
+ " * `if` Statements\n",
+ " * `if` - `else` Statements\n",
+ " * `if` - `elif` - `else` Statements\n",
+ " * Logical operators (`and`, `or`, `not`)\n",
+ " * Operator Precedence\n",
" \n",
" \n",
- "5. Iteration (Loops)\n",
- " * `for` Loop\n",
- " * `while` Loop\n",
- " * Nested Loops\n",
- " * `break` and `continue`\n",
+ "5. Iteration (Loops)\n",
+ " * `for` Loop\n",
+ " * `while` Loop\n",
+ " * Nested Loops\n",
+ " * `break` and `continue`\n",
" \n",
"\n",
- "6. User Defined Functions\n",
- " * Introduction\n",
- " * Defining Functions\n",
- " * Calling Functions\n",
- " * Arguments and Parameters\n",
- " * Variable Scope\n",
+ "6. User Defined Functions\n",
+ " * Introduction\n",
+ " * Defining Functions\n",
+ " * Calling Functions\n",
+ " * Arguments and Parameters\n",
+ " * Variable Scope\n",
" \n",
" \n",
- "7. Collections: Lists, Dictionaries, Sets, Tuples\n",
- " * Creating\n",
- " * Accessing Data\n",
- " * Functions - Returning Multiple Values\n",
- " * Functions - Pass by Value; Pass by Reference\n",
+ "7. Collections: Lists, Dictionaries, Sets, Tuples\n",
+ " * Creating\n",
+ " * Accessing Data\n",
+ " * Functions - Returning Multiple Values\n",
+ " * Functions - Pass by Value; Pass by Reference\n",
"\n",
" \n",
- "8. File I/O\n",
- " * Modes: read (`'r'`), write (`'w'`), append(`'a'`)\n",
- " * Ways to Read: `read()`, `readline()`, `readlines()`\n",
- " * Writing and Closing: `write()`, `close()`\n",
+ "8. File I/O\n",
+ " * Modes: read (`'r'`), write (`'w'`), append(`'a'`)\n",
+ " * Ways to Read: `read()`, `readline()`, `readlines()`\n",
+ " * Writing and Closing: `write()`, `close()`\n",
" \n",
"\n",
- "9. Hashing\n",
- " * Hashing Strings\n",
+ "9. Hashing\n",
+ " * Hashing Strings\n",
"\n",
"\n",
- "10. Exception Handling\n",
- " * Catching exceptions\n",
- " * Raising exceptions\n",
- "\n",
- "\n",
- "11. Recursion\n",
- " * Introduction\n",
- " * Examples\n",
+ "10. Exception Handling\n",
+ " * Catching exceptions\n",
+ " * Raising exceptions\n",
+ " \n",
+ "11. Recursion\n",
+ " * Introduction\n",
+ " * Examples\n",
"\n",
"\n",
- "12. OOP\n",
- " * User-defined Classes\n",
+ "12. OOP\n",
+ " * User-defined Classes\n",
"\n",
"\n",
- "13. Misc Topics"
+ "13. Misc Topics\n"
]
},
{
diff --git a/content/01_intro00.ipynb b/content/01_intro00.ipynb
index fb38972..ce37493 100644
--- a/content/01_intro00.ipynb
+++ b/content/01_intro00.ipynb
@@ -15,15 +15,14 @@
"source": [
"### Quickstart Guide for Jupyter Notebooks:\n",
"\n",
- "* Jupyter Notebooks are arranged as a collection of \"cells\". Cells can contain instructions / descriptions or code.\n",
+ "* Jupyter Notebooks are arranged as a collection of \"cells\". Cells can contain descriptions or code.\n",
"* A cell is selected if you see a blue bar to its left.\n",
"* To minimize a cell, click once on its blue bar. Click the blue bar again to expand.\n",
"* To edit a code cell, click on it.\n",
"* To run a code cell, make sure it's selected and press **Cntl-Enter**.\n",
" * You can repeatedly run a cell as long as it's highlighted. Each re-run of a cell will start by clearing its output.\n",
"* To clear the output in a code cell: Right-click it; select **Clear Outputs**.\n",
- "* To clear the output for all code cells in a notebook, right-click on the window and select **Clear All Outputs**\n",
- "* If a particular code cell appears to \"hang\" or won't run, select **Restart Kernel...** from the **Kernel** menu."
+ "* To clear the output for all code cells in a notebook, right-click on the window and select **Clear All Outputs**"
]
},
{
@@ -34,7 +33,7 @@
"
\n",
"
\n",
"\n",
- "Throughout these notebooks, you'll occasionally see a green check mark like the one shown above. These are knowledge checkpoints intended to test your skills and understanding of the material. They usually involve asking a question before having you run a snippet of code to check your answer.\n",
+ "Throughout these notebooks you'll occasionally see a green check mark like the one shown above. These are knowledge checkpoints intended to test your skills and understanding of the material. They usually involve asking a question before having you run a snippet of code to check your answer.\n",
"
"
]
},
@@ -51,7 +50,6 @@
"metadata": {},
"source": [
"- To run the code below, click (once) on the code block, hold the `Control` key and press the `Enter` key (`Cntl-Enter`).\n",
- "- This code example is interactive and will ask you for input.\n",
"- To re-run the code, press `Cntl-Enter` again.\n",
"- To clear the output, right-click on the cell and select `Clear Outputs`"
]
@@ -87,7 +85,7 @@
"source": [
"### If Code Cells Won't Clear or Run\n",
"\n",
- "Occasionally jupyter lab will appear to \"hang\" when running a code cell. This is often because some code in the backround is waiting for input or is dealing with an error condition. Take the example below, which prints `Hello`, then goes into a loop that runs forever (what's called an [infinite loop](https://en.wikipedia.org/wiki/Infinite_loop)). As a result, `Goodbye` never prints to the screen and jupyter lab appears to be unresponsive; no other code cells will run.\n",
+ "Occasionally jupyter lab will appear to \"hang\" when running a code cell. This is often because some code in the background is waiting for input or is dealing with an error condition. Take the example below, which prints `Hello`, then goes into a loop that runs forever (what's called an [infinite loop](https://en.wikipedia.org/wiki/Infinite_loop)). As a result, `Goodbye` never prints to the screen and jupyter lab appears to be unresponsive; no other code cells will run.\n",
"\n",
"Try running the code cell below. You should see `Hello` print to the screen, then nothing. Clear the cell and try to run it again. Notice that nothing happens. You'll know that the cell is unresponsive because you'll see an asterisk next to the top of the cell. If that happens, just press the *Interrupt the kernel* button (small square at the top of the window) to reset it."
]
@@ -117,11 +115,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "### If You Accidently Double-click a Text Cell\n",
+ "### If You Accidentally Double-click a Text Cell\n",
"\n",
"Don't worry :-)\n",
"\n",
- "If you double-click a text cell you put it in *edit mode*. Text cells are written in a language called [markdown](https://www.markdownguide.org/getting-started/) and double-clicking on one allows you to edit the underlying content. If you accidently double-click on one, just \"run\" the cell like you would a code cell (holding the `Control` key and pressing the `Enter` key). This will put it back into *display mode*. Go ahead and try it. Double-click this cell to enter *edit mode*, then press `Control-Enter` to put it back into *display mode*.\n",
+ "If you double-click a text cell you put it in *edit mode*. Text cells are written in a language called [markdown](https://www.markdownguide.org/getting-started/) and double-clicking on one allows you to edit the underlying content. If you accidentally double-click on one, just \"run\" the cell like you would a code cell (holding the `Control` key and pressing the `Enter` key). This will put it back into *display mode*. Go ahead and try it. Double-click this cell to enter *edit mode*, then press `Control-Enter` to put it back into *display mode*.\n",
"\n",
"You shouldn't have a need to manipulate text cells in these notebooks, but if you put one in *edit mode* by mistake, now you know how to put it back into *display mode*."
]
@@ -145,7 +143,7 @@
"source": [
"## Additional Resources\n",
"\n",
- "There is so much more to Jupyter Notebooks than what's listed above, but it will get you started. Trying Googling \"Jupyter Notebooks\", or check out some of these resources:\n",
+ "There is so much more to Jupyter Notebooks than what's listed above, but it will get you started. Trying Googling `Jupyter Notebooks`, or check out some of these resources:\n",
"\n",
"*NOTE: Jupyter Lab is the next evolution of the Jupyter infrastructure. The basic program (jupyter notebook) started it all.*\n",
"\n",
diff --git a/content/01_intro01.ipynb b/content/01_intro01.ipynb
index 53c1b0f..c52b2d1 100644
--- a/content/01_intro01.ipynb
+++ b/content/01_intro01.ipynb
@@ -40,7 +40,7 @@
"
\n",
"
\n",
"\n",
- "Do you remember how to run a code cell? Visit the first jupyter notebook if you need a refresher. To test your knowledge, run the code cell above and observe the output. Then modify the program to print your name, rather than `Hello World` and run it again."
+ "Do you remember how to run a code cell? Visit [this jupyter notebook](./01_intro00.ipynb) if you need a refresher. To test your knowledge, run the code cell above and observe the output. Then modify the program to print your name, rather than `Hello World` and run it again."
]
},
{
@@ -49,7 +49,7 @@
"source": [
"While this first program is very simple, it introduces an important concept: Having Python print information to the screen. A computer program that only calculated results, but never provided them to you would not be very useful.\n",
"\n",
- "In the first notebook we introduced this Python program:"
+ "In the [first notebook](01_intro00.ipynb) we introduced this Python program:"
]
},
{
@@ -107,7 +107,7 @@
"\n",
"Python is quite forgiving about how things are spaced-out. If often comes down to readability. Can you (or your instructor) easily read your code and follow along? While the program may run just fine, be mindful that you can change the intended result because of the particular spacing you used.\n",
"\n",
- "Here are some examples:"
+ "Below are some examples. Run them and observe the outputs."
]
},
{
diff --git a/content/02_operations00.ipynb b/content/02_operations00.ipynb
index 94bf4e7..221cb93 100644
--- a/content/02_operations00.ipynb
+++ b/content/02_operations00.ipynb
@@ -101,7 +101,7 @@
"1. Evaluate everything to the right of `=`. That means, take the current value in `score` (45) and add 10 to it.\n",
"2. Take the result from step 1 and store it in the variable named `score`. This replaces `score`'s original value (45) with the newly calculated value (55).\n",
"\n",
- "It's important to understand that the steps are followed in the order given above. Before we replace `score` with a new value, we use the current value in `score` to calculate an interim result, then place that result back into `score`.\n",
+ "It's important to understand that the steps are followed in the order given above. Before we replace `score` with a new value, we use the current value in `score` to calculate an interim result, then place that interim result back into `score`.\n",
"\n",
"You will see and use this design pattern often in any programming language you learn, including Python."
]
@@ -130,7 +130,7 @@
"source": [
"
\n",
"\n",
- "How about getting input from the user? User input and output is such a fundamental and common part of most programs that it's worth taking time to make sure you understand it well. A very common way to collect user input is with Python's `input()` function. Here's an example:"
+ "How about getting input from the user? User input and output is such a fundamental and common part of most programs that it's worth taking time to make sure you understand it well. A very common way to collect user input is with Python's [input()](https://docs.python.org/3/library/functions.html#input) function. Here's an example:"
]
},
{
@@ -149,10 +149,10 @@
"source": [
"There are several important things happening in those two lines of code:\n",
"\n",
- "1. `input()` is a Python function that takes a string which represents the prompt you want to see on the screen (*Note: a string is a collection of characters. We'll examine strings in more detail in the next notebook*).\n",
- "2. The `input()` function prints the prompt the screen, then pauses program execution while waiting for the user to type something in. The `input()` function knows the input is complete when the user presses the `return` key.\n",
+ "1. [input()](https://docs.python.org/3/library/functions.html#input) is a Python function that takes a string which represents the prompt you want to see on the screen (*Note: a string is a collection of characters. We'll examine strings in more detail in the next notebook*).\n",
+ "2. The [input()](https://docs.python.org/3/library/functions.html#input) function prints the prompt the screen, then pauses program execution while waiting for the user to type something in. The [input()](https://docs.python.org/3/library/functions.html#input) function knows the input is complete when the user presses the `return` key.\n",
"3. The input function returns whatever the user types and stores it in the variable `name`.\n",
- "4. Finally, the `print()` function prints the ***value*** stored in `name` to the screen (it doesn't print the characters `n` `a` `m` `e` to the screen)."
+ "4. Finally, the `print()` function prints the ***value*** stored in `name` to the screen (*it doesn't print the characters `n` `a` `m` `e` to the screen*)."
]
},
{
@@ -161,7 +161,7 @@
"source": [
"### Basic Arithmetic Operations\n",
"\n",
- "Like all modern programming languages, Python provides support for basic [arithmetic operations](https://docs.python.org/3.3/reference/expressions.html#binary). Here are the big four:\n",
+ "Like all modern programming languages, Python provides support for basic [arithmetic operations](https://docs.python.org/3/reference/expressions.html#binary). Here are the big four:\n",
"\n",
"- Addition: `+`\n",
"- Subtraction: `-`\n",
@@ -250,7 +250,7 @@
"source": [
"### Operator Precedence\n",
"\n",
- "Precedence refers to the order in which mathematical operations are performed. The order of [operator precedence in Python](https://docs.python.org/3/reference/expressions.html#operator-summary) is as follows:\n",
+ "Precedence refers to the order in which mathematical operations are performed. The order of [operator precedence in Python](https://docs.python.org/3/reference/expressions.html#operator-summary) for the operators we've seen is as follows:\n",
"\n",
"1. Exponentiation (`**`)\n",
"2. Multiplication (`*`), float division (`/`), [integer division](https://docs.python.org/3/reference/expressions.html#binary) (`//`), [modulo](https://docs.python.org/3/reference/expressions.html#binary) (`%`)\n",
@@ -263,7 +263,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "#### What does this code print?"
+ "What does this code print (calculate it on paper first, then run the code)?"
]
},
{
@@ -282,7 +282,7 @@
"source": [
"
\n",
"\n",
- "#### How about now?"
+ "How about now?"
]
},
{
@@ -301,7 +301,7 @@
"source": [
"
\n",
"\n",
- "Notice how we can change how precedence is enforced with parentheses. Even if a line of code performs as intended without parenthesis, adding them can often make the code easier to follow, and debug if necessary. For example, `x` and `y` evaluate to the same number below, but the expression in `y` makes it unambiguous what the programmer intended."
+ "Notice how we can change how precedence is enforced with parentheses. Even if a line of code performs as intended without parenthesis, adding them can often make the code easier to follow and debug if necessary. For example, `x` and `y` evaluate to the same number below, but the expression in `y` makes it unambiguous what the programmer intended."
]
},
{
diff --git a/content/02_operations01.ipynb b/content/02_operations01.ipynb
index 0a2b609..ad513f4 100644
--- a/content/02_operations01.ipynb
+++ b/content/02_operations01.ipynb
@@ -135,8 +135,6 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "#### What happened?\n",
- "\n",
"Sample 3 is interesting. Why doesn't it crash? Doesn't Sample 2 demonstrate that you can't add strings?\n",
"\n",
"Not exactly. Sample 2 demonstrates that you can't add a string to an integer. Sample 3 demonstrates that you can merge two (or more) strings together using the `+` operator, and the result is a new string that represents the combination of the two. The term for combining strings in this way is *concatenation*.\n",
@@ -228,7 +226,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "Sample 2 shows a simple form of iteration to print every character in a string. It's a good start, but we'll explore more sophisticated iteration techniques throughout the course. Also note that a `space` is also considered a character (the character at `s[2]`)."
+ "Sample 2 shows a simple form of iteration to print every character in a string. It's a good start, but we'll explore more sophisticated iteration techniques throughout the course. Also note that a `space` is considered a character (the character at `s[2]`)."
]
},
{
@@ -267,7 +265,7 @@
"source": [
"#### __*immutable*__\n",
"\n",
- "If something is immutable, it means that once it's created, it can't be changed. Mutability can be a confusing topic, so we'll explore with examples.\n",
+ "If something is immutable, it means that once it's created it can't be changed. Mutability can be a confusing topic, so we'll explore with examples.\n",
"\n",
"Strings are immutable. While you can change the entire value of a string in a variable, you cannot change the value of an individual character *inside* a string variable.\n",
"\n",
@@ -388,7 +386,7 @@
"\n",
"Can we create a string variable without any characters in it? The answer is, yes. It's a very handy and frequently used design pattern.\n",
"\n",
- "Remember this example from the previous notebook that shows a variable (`score`) on both sides of the equal sign?"
+ "Remember this example from the [previous notebook](02_operations00.ipynb) that shows a variable (`score`) on both sides of the equal sign?"
]
},
{
diff --git a/content/02_operations02.ipynb b/content/02_operations02.ipynb
index 73f2b36..6714a92 100644
--- a/content/02_operations02.ipynb
+++ b/content/02_operations02.ipynb
@@ -84,7 +84,7 @@
"\n",
"`Here is a directory path in MS-Windows: c:\\smith\\Documents`\n",
"\n",
- "The definition above still holds; just use two backslashes!"
+ "The definition above still holds. Just use two backslashes!"
]
},
{
@@ -103,7 +103,7 @@
"source": [
"### Accessing individual characters (revisited)\n",
"\n",
- "In the first notebook on strings we examined how to access individual characters. The example we gave was pretty straightforward because we chose the string to manipulate. What happens if you don't know the string in advance? What if you prompt the user for a string and then need to find specific characters?\n",
+ "In the [first notebook on strings](02_operations01.ipynb) we examined how to access individual characters. The example we gave was pretty straightforward because we chose the string to manipulate. What happens if you don't know the string in advance? What if you prompt the user for a string and then need to find specific characters?\n",
"\n",
"Here's an example of finding the length of a user-entered string and accessing individual characters."
]
@@ -118,7 +118,7 @@
"length = len(s)\n",
"print(\"Number of characters in your string:\", length)\n",
"print(\"The first character in your string is:\", s[0])\n",
- "print(\"The last character in your string is:\", s[length-1])"
+ "print(\"The last character in your string is:\", s[-1])"
]
},
{
@@ -134,17 +134,19 @@
"source": [
"### String Slicing\n",
"\n",
- "Carving up strings in python is known as *slicing*. While strings are immutable (unchangable), you can still slice parts of them and assemble the parts (concatenate them) in various ways. Here are some syntax rules for various slicing operations (assume we have a string variable called `s`):\n",
+ "Carving up strings in python is known as *slicing*. While strings are immutable (unchangeable), you can still slice parts of them and assemble the parts (concatenate them) in various ways. Here are some syntax rules for various slicing operations (assume we have a string variable called `s`):\n",
"\n",
- "`s[start:end]` From the character at position `start` to the character at position `end`-1.\n",
+ "`s[start:end]` The substring in `s` from the character at position `start` to the character at position `end`-1.\n",
"\n",
- "`s[start:]` From the character at position `start` to the end of the string.\n",
+ "`s[start:]` The substring in `s` from the character at position `start` to the end of the string.\n",
"\n",
- "`s[:end]` From the beginning of the string to the character at position `end`-1.\n",
+ "`s[:end]` The substring in `s` from the beginning of the string to the character at position `end`-1.\n",
"\n",
"`s[:]` A complete copy of `s`.\n",
"\n",
- "Here are some coding examples of slicing a string:"
+ "
\n",
+ "\n",
+ "Below is an example of slicing a string. Try to predict what will be printed, then run the code to check your work."
]
},
{
@@ -168,7 +170,7 @@
"source": [
"### A roundabout way to mutate a string using slicing\n",
"\n",
- "In the first string notebook, I said that you can't mutate a string (change individual characters). So, for example, how would we insert a new word into the middle of a string?"
+ "In the [first string notebook](02_operations01.ipynb), I said that you can't mutate a string (change individual characters). So, for example, how would we insert a new word into the middle of a string? The code below demonstrates on technique:"
]
},
{
@@ -198,7 +200,7 @@
"source": [
"### Type Conversions\n",
"\n",
- "So far our use of Python's `input()` function has been limited to string data, but what about getting numerical input from the user? Run the code below."
+ "So far our use of Python's [input()](https://docs.python.org/3/library/functions.html#input) function has been limited to string data, but what about getting numerical input from the user? Run the code below."
]
},
{
@@ -217,7 +219,7 @@
"source": [
"
\n",
"\n",
- "Interesting, right? It doesn't crash, but it doesn't exactly do what we want. That's because Python's `input()` function assumes that everything you type is a string, and if you want it to represent some other type it's up to you to do the conversion. So how do you convert the string `\"5\"` into the integer `5`? Use Python's [int()](https://docs.python.org/3/library/functions.html) function."
+ "Interesting, right? It doesn't crash, but it doesn't exactly do what we want. That's because Python's [input()](https://docs.python.org/3/library/functions.html#input) function assumes that everything you type is a string, and if you want it to represent some other type it's up to you to do the conversion. So how do you convert the string `\"5\"` into the integer `5`? Use Python's [int()](https://docs.python.org/3/library/functions.html) function."
]
},
{
@@ -237,7 +239,7 @@
"source": [
"
\n",
"\n",
- "Converting data from one type to another is called *casting*. When casting input to integers a common technique is to combine the use of `int()` with `input()` like this:"
+ "Converting data from one type to another is called *casting*. When casting input to integers, a common technique is to combine the use of [int()](https://docs.python.org/3/library/functions.html) with [input()](https://docs.python.org/3/library/functions.html#input) on a single line like this:"
]
},
{
@@ -256,7 +258,7 @@
"source": [
"
\n",
"\n",
- "You can use `int()` to cast floats to ints as well. What happens when you run the code below?"
+ "You can use [int()](https://docs.python.org/3/library/functions.html) to cast floats to ints as well. What happens when you run the code below?"
]
},
{
diff --git a/content/03_builtinFunctions00.ipynb b/content/03_builtinFunctions00.ipynb
index 347df3e..a4b6779 100644
--- a/content/03_builtinFunctions00.ipynb
+++ b/content/03_builtinFunctions00.ipynb
@@ -11,7 +11,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "Python includes many built-in functions to accomplish tasks. A good list of Python's basic built-ins is available [here](https://docs.python.org/3/library/functions.html). We've already explored several (`input()`, `int()`, `str()`, etc.), and we'll take a look at many more throughout the course.\n",
+ "Python includes many built-in functions to accomplish tasks. A good list of Python's basic built-ins is available [here](https://docs.python.org/3/library/functions.html). We've already explored several ([input()](https://docs.python.org/3/library/functions.html), [int()](https://docs.python.org/3/library/functions.html), [str()](https://docs.python.org/3/library/functions.html), etc.), and we'll take a look at many more throughout the course.\n",
"\n",
"In addition to Python's built-in functions, you can extend its capabilities by importing libraries (or modules) that contain additional functionality. When you install Python it includes many useful libraries that go beyond the built-in functions, and it even allows you to write your own libraries that you can share with others.\n",
"\n",
@@ -33,7 +33,7 @@
"source": [
"
\n",
"\n",
- "Once we import the library, we can use a particular function that it provides by using \"dot\" (.) notation. That's the module name (`math`) followed by a period, then followed by the name of the function you want to use. Here's an example of using the `factorial` function in Python's `math` library: "
+ "Once we import the library, we can use a particular function that it provides by using \"dot\" (.) notation. That's the module name ([math](https://docs.python.org/3/library/math.html)) followed by a period, then followed by the name of the function you want to use. Here's an example of using the `factorial` function in Python's [math](https://docs.python.org/3/library/math.html) library: "
]
},
{
@@ -120,8 +120,8 @@
"\n",
"Bring it all together. Write a program in the code block below that does the following:\n",
"\n",
- "- Prompt the user for a radius (hint: use `input()` and cast the results to a float using `float()`)\n",
- "- Use Python's `math` library to calculate pi, compute the area of the circle and print the result to the screen with a suitable message (e.g. *The area of your circle is: * "
+ "- Prompt the user for a radius (hint: use [input()](https://docs.python.org/3/library/functions.html) and cast the results to a float using [float()](https://docs.python.org/3/library/functions.html))\n",
+ "- Use Python's [math](https://docs.python.org/3/library/math.html) library to calculate pi, compute the area of the circle and print the result to the screen with a suitable message (e.g. *The area of your circle is: * "
]
},
{
@@ -196,7 +196,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "How do you know whether a method returns a copy of an object or modifies the object itself? The best way is [check the documentation](https://docs.python.org/3/). In this case, though, since string objects are immutable it's a good guess that most methods that operate on string objects return copies.\n",
+ "How do you know whether a method returns a copy of an object or modifies the object itself? The best way is to [check the documentation](https://docs.python.org/3/). In this case, though, since string objects are immutable it's a good guess that most methods that operate on string objects return copies.\n",
"\n",
"Here are some more examples:"
]
@@ -224,8 +224,8 @@
"# Without explanation, what does this string method do?\n",
"\n",
"s = \"Now colleges from sea to sea may sing of colors true!\"\n",
- "number = s.count(\"ol\")\n",
- "print(number)"
+ "n = s.count(\"ol\")\n",
+ "print(n)"
]
},
{
diff --git a/content/03_builtinFunctions01.ipynb b/content/03_builtinFunctions01.ipynb
index 89958ee..4057a84 100644
--- a/content/03_builtinFunctions01.ipynb
+++ b/content/03_builtinFunctions01.ipynb
@@ -11,7 +11,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "So far, we've just used Python's `print()` function to send output the screen. It's simple and it works well, but what if we want to format the output in a particular way? Consider this example:"
+ "So far, we've just used Python's [print()](https://docs.python.org/3/library/functions.html) function to send output the screen. It's simple and it works well, but what if we want to format the output in a particular way? Consider this example:"
]
},
{
@@ -34,9 +34,9 @@
"\n",
"To answer that question, we first need to understand something called a *format specifier*.\n",
"\n",
- "A format specifier is a placeholder in Python that says: *Don't actually print the placeholder you see here, but fill it in with something that I'll provide to you later.* We denote format specifiers in Python strings by using curly braces `{}` and a number indicating the position of the placeholder (always start counting from `0`). We follow that with the `format()` method and a comma-separated list of items to fill in the placeholders.\n",
+ "A format specifier is a placeholder in Python that says: *Don't actually print the placeholder you see here, but fill it in with something that I'll provide to you later.* We denote format specifiers in Python strings by using curly braces `{}` and a number indicating the position of the placeholder (always start counting from `0`). We follow that with the [format()](https://docs.python.org/3/library/stdtypes.html#str.format) method and a comma-separated list of items to fill in the placeholders.\n",
"\n",
- "Here's an example (run the code):"
+ "Lots of words! Here's an example (run the code):"
]
},
{
@@ -54,10 +54,10 @@
"source": [
"- What gets printed?\n",
"- What if you switch the `0` and `1`?\n",
- "- What if you switch `Navy` and `Army` within the `format()` method?\n",
+ "- What if you switch `Navy` and `Army` within the [format()](https://docs.python.org/3/library/stdtypes.html#str.format) method?\n",
"- What if you delete `Army` so the line reads: `print(\"Go {0}! Beat {1}!\".format(\"Navy\"))`\n",
"\n",
- "To reinforce: format specifiers in Python are positional references that map, one for one, to each item in a comma separated listing of items contained in the `format()` method. In Object Oriented Programming terms, `format()` is a method that operates on string objects.\n",
+ "To reinforce: format specifiers in Python are positional references that map, one for one, to each item in a comma separated listing of items contained in the [format()](https://docs.python.org/3/library/stdtypes.html#str.format) method. In Object Oriented Programming terms, [format()](https://docs.python.org/3/library/stdtypes.html#str.format) is a method that operates on string objects.\n",
"\n",
"You can add a qualifier to a format specifier to refine how the output is displayed. In the coming examples, we'll see that these qualifiers can be incredibly powerful. Available qualifiers are shown below:\n",
"\n",
@@ -194,7 +194,8 @@
"metadata": {},
"source": [
"
\n",
- "You can switch the order of format specifiers. Just remember that items in the format listing are *zero-based indexed*, meaning we always start counting from `0`. For example, if there were two items in a `format()` statement they would be numbered `0` and `1`."
+ "\n",
+ "You can switch the order of format specifiers. Just remember that items in the format listing are ***zero-based indexed***, meaning we always start counting from `0`. For example, if there were two items in a [format()](https://docs.python.org/3/library/stdtypes.html#str.format) statement they would be numbered `0` and `1`."
]
},
{
@@ -214,6 +215,7 @@
"metadata": {},
"source": [
"
\n",
+ "\n",
"The code below shows how to align text within a given allocation of characters (25 in this case)."
]
},
@@ -229,17 +231,6 @@
"print(\"{0:>25s}\".format(s)) # Align right"
]
},
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "
\n",
- "
\n",
- "
\n",
- "\n",
- "Why does the code above output two lines when there's only one `print()` statement? It has to do with the `\\n` at the end of the string assigned to the variable `s1`. Recall that `\\` is the [escape character](https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals) in a string; it indicates that what comes after the `\\` has special meaning. In Python, `\\n` means insert a new line. "
- ]
- },
{
"cell_type": "markdown",
"metadata": {},
@@ -266,7 +257,7 @@
"source": [
"
\n",
"\n",
- "You can use format specifiers to convert between number bases. Note that even though I'm using one value (`n`), I need to list it twice within the `format()` method. For every specifier enclosed in `{}` within a string, you must have a positional partner in the listing within the `format()` method."
+ "You can even use format specifiers to convert between number bases! Note that even though I'm using one value (`n`), I need to list it twice within the [format()](https://docs.python.org/3/library/stdtypes.html#str.format) method. For every specifier enclosed in `{}` within a string, you must have a positional partner in the listing within the [format()](https://docs.python.org/3/library/stdtypes.html#str.format) method."
]
},
{
@@ -285,7 +276,7 @@
"source": [
"
\n",
"\n",
- "You can use format specifiers to specify a certain number of decimal places of precision. If no value is specified for the number of decimal places in a floating point number, the default is six. Note that you can also perform calculations inside the `format()` method."
+ "You can use format specifiers to specify a certain number of decimal places of precision. If no value is specified for the number of decimal places in a floating point number, the default is six. Note that you can also perform calculations inside the [format()](https://docs.python.org/3/library/stdtypes.html#str.format) method."
]
},
{
@@ -298,6 +289,17 @@
"print(\"n = {0:d} and 1/n = {1:f}. The value of 1/n to two places = {2:.2f}\".format(n,1/n,1/n))"
]
},
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The print statement above is a little complex, but just follow the numbers. Each format specifier has a positional partner in the [format()](https://docs.python.org/3/library/stdtypes.html#str.format) method.\n",
+ "\n",
+ "
\n",
+ "
\n",
+ "
"
+ ]
+ },
{
"cell_type": "markdown",
"metadata": {},
@@ -342,7 +344,7 @@
"source": [
"
\n",
"\n",
- "Forcing a sign on numeric values. The default for negative numbers is to display the sign."
+ "You can place a sign on numeric values. The default for negative numbers is to display the sign."
]
},
{
@@ -362,7 +364,7 @@
"source": [
"
\n",
"\n",
- "Padding with leading zeros. This can be tricky. When padding, the number specified indicates the *maximum* total display length, including any signs and / or decimal points. If the maximum length already exceeds the padding specifier, then no leading zeros are applied. Run the example below and examine the output and the code to understand how padding with zeros works."
+ "You can pad with leading zeros. This can be tricky. When padding, the number specified indicates the *maximum* total display length, including any signs and / or decimal points. If the maximum length already exceeds the padding specifier, then no leading zeros are applied. Run the example below and examine the output and the code to understand how padding with zeros works."
]
},
{
@@ -412,7 +414,7 @@
"source": [
"
\n",
"\n",
- "Here's how it's done using a format specifier, with a decimal (`d`) qualifier, and a comma indicator:"
+ "Here's how it's done using a format specifier, with a decimal (`d`) qualifier and a comma indicator:"
]
},
{
diff --git a/content/04_branchlogic00.ipynb b/content/04_branchlogic00.ipynb
index 1cf950f..38791b9 100644
--- a/content/04_branchlogic00.ipynb
+++ b/content/04_branchlogic00.ipynb
@@ -14,9 +14,9 @@
"\n",
"A few other points:\n",
"\n",
- "* The boolean values for `True` and `False` are written without quotation marks (they're not strings)\n",
+ "* The Boolean values for `True` and `False` are written without quotation marks (they're not strings)\n",
"* The words are [case-sensitive](https://www.computerhope.com/jargon/c/casesens.htm), meaning the character case is specific. `True` is not the same as `true`.\n",
- "* In many other computer languages, `True` is represented by the integer `1`, and `False` is represented by the integer `0`.\n",
+ "* In many other computer languages, `True` is represented by the integer `1`, and `False` is represented by the integer `0`. In the C programming language, the integer '0' represents `False` and any other number (including floats and negative numbers) represents `True`.\n",
"\n",
"Let's look at a programming example with a simple mathematical statement: `2` is greater than `1` (coded as: `2 > 1`). When you run the code below, what gets printed?"
]
@@ -34,7 +34,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "Remember, the result is not the string `\"True\"`, it's a boolean value `True`.\n",
+ "Remember, the result is not the string `\"True\"`, it's a Boolean value `True`.\n",
"\n",
"
\n",
"\n",
@@ -125,7 +125,7 @@
"Some key elements in the code above:\n",
"\n",
"* `if` is a reserved word; you can't have a variable named `if`.\n",
- "* What follows `if` is an expression that must evaluate to a boolean result (`True` or `False`).\n",
+ "* What follows `if` is an expression that must evaluate to a Boolean result (`True` or `False`).\n",
"* The colon (`:`) at the end of line 2 is an important and required element.\n",
"* The `print()` statement in line 3 is indented to the right below line 2. This is our first time exploring [indentation in Python](https://docs.python.org/3/faq/design.html?highlight=indentation#why-does-python-use-indentation-for-grouping-of-statements), but it's a critical part of the language. Lines of code (and there can be multiple) that are indented following a colon are specifically grouped to apply to the line with the colon. Many of the errors you'll wrestle with in Python result from improper indentation.\n",
"\n",
@@ -177,11 +177,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "Some inportant points about the code above:\n",
+ "Some important points about the code above:\n",
"\n",
- "* Remember that `input()` always returns a string. As a result, we have to cast whatever the user enters into an integer using Python's [int() function](https://docs.python.org/3/library/stdtypes.html#typesnumeric).\n",
+ "* Remember that `input()` always returns a string. As a result, we have to cast whatever the user enters into an integer using Python's [int()](https://docs.python.org/3/library/stdtypes.html#typesnumeric) function.\n",
"* You can easily crash the program by typing something other than a valid integer (e.g. `Hello`). Give it a try! What error message do you get?\n",
- "* If you entered an integer that was less than or equal to 20, what happened? Would it be better to print something like, \"*You entered an integer less than or equal to 20*\"? We'll explore that next.\n",
+ "* If you entered an integer that was less than or equal to 20, what happened? Wouldn't it be better to print something like, \"*You entered an integer less than or equal to 20*\"? Yes, it would! We'll explore that next.\n",
"\n",
"### What `else` Can You Do With `if`?\n",
"\n",
@@ -222,7 +222,7 @@
"With an `if`-`else` statement, you can think of its execution as a binary choice. Do *this* or *that*. It's a great start, but very often your program logic requires decisions that flow like this: *If something is true, then do this; else if this other thing is true, then do that; else if this other thing is true, then do that.....etc., etc.* What we need is a compound statement that allows for multiple branches in our logic, like this:\n",
"\n",
"
\n",
- "
\n",
+ "
\n",
"
\n",
"\n",
"Python provides just that! Rather than completely spelling out `else if`, it's written as a compound expression like this: `elif`.\n",
diff --git a/content/04_branchlogic01.ipynb b/content/04_branchlogic01.ipynb
index b0adfc3..8e3be8f 100644
--- a/content/04_branchlogic01.ipynb
+++ b/content/04_branchlogic01.ipynb
@@ -6,25 +6,25 @@
"source": [
"# Logical Operators\n",
"\n",
- "Logical operators allow us to move to more complex boolean expressions. Take this simple expression that you might write in algebra:\n",
+ "Logical operators allow us to move to more complex Boolean expressions. Take this simple expression that you might write in algebra:\n",
"\n",
"
\n",
- "
\n",
+ "
\n",
"
\n",
"\n",
"Now consider this one, which is a little more complex:\n",
"\n",
"
\n",
- "
\n",
+ "
\n",
"
\n",
"\n",
"For this more complex expression, you might say it like this: \"*x is greater than three and x is less than or equal to 20.*\"\n",
"\n",
- "What we need is an operator that performs like a [conjunction](https://www.youtube.com/watch?v=RPoBE-E8VOc) in English grammar to join boolean expressions together. Python provides these [logical operators](https://docs.python.org/3/reference/expressions.html#not) for us. Here are the ones you'll use most often:\n",
+ "What we need is an operator that performs like a [conjunction](https://www.youtube.com/watch?v=RPoBE-E8VOc) in English grammar to join Boolean expressions together. Python provides these [logical operators](https://docs.python.org/3/reference/expressions.html#not) for us. Here are the ones you'll use most often:\n",
"\n",
"* `and`: Returns `True` if both statements are true. Example: x > 3 `and` x <= 20)\n",
"* `or`: Returns `True` if at least one of the statements is true. Example: x > 3 `or` x <= 20\n",
- "* `not`: Reverse the result, returns `False` if the result is true. Example: `not` (x > 3 and x <= 20))\n",
+ "* `not`: Reverse the result, returns `False` if the result is `True`. Example: `not` (x > 3 and x <= 20))\n",
"\n",
"\n",
"### Examples\n",
@@ -54,7 +54,7 @@
"source": [
"
\n",
"\n",
- "How about this one, using: 5, 3, 25, 0?"
+ "Try this one (use 5, 3, 25, 0):"
]
},
{
@@ -104,15 +104,13 @@
"source": [
"### Operator Precedence\n",
"\n",
- "Boolean operators have a [precedence ranking](https://docs.python.org/3/reference/expressions.html#operator-summary), just like arithmetic operators. For boolean operators the order of precedence (highest to lowest) is:\n",
+ "Boolean operators have a [precedence ranking](https://docs.python.org/3/reference/expressions.html#operator-summary), just like arithmetic operators. For Boolean operators the order of precedence (highest to lowest) is:\n",
"\n",
"* `not`\n",
"* `and`\n",
"* `or`\n",
"\n",
- "To understand this, guess what will be produced when you run the code below with an input of 25, then run it to test your prediction.\n",
- "\n",
- "*Also try other values to further test your understanding.*"
+ "To understand this, guess what will be produced when you run the code below with an input of 25, then run it to test your prediction."
]
},
{
@@ -135,6 +133,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
+ "*Also try other values to further test your understanding.*\n",
+ "\n",
"## Additional Resources\n",
"\n",
"[Python operator precedence](https://docs.python.org/3/reference/expressions.html#operator-summary)\n",
diff --git a/content/05_iteration00.ipynb b/content/05_iteration00.ipynb
index da480bc..294c1e6 100644
--- a/content/05_iteration00.ipynb
+++ b/content/05_iteration00.ipynb
@@ -6,9 +6,9 @@
"source": [
"# Iteration (Looping)\n",
"\n",
- "Iteration if a fancy term for *looping*. When you want to peform the same operation over-and-over on a collection of data elements, then iterating is the way to do it.\n",
+ "Iteration if a fancy term for *looping*. When you want to perform the same operation over-and-over on a collection of data elements, then iterating is the way to do it.\n",
"\n",
- "Let's revisit this example from our discussion of strings:"
+ "Let's revisit this example from our [introduction to strings](02_operations01.ipynb):"
]
},
{
@@ -31,13 +31,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "The code is pretty straightforward: create a string (`s`) that contains `\"Go Navy\"`, then print out every character in the string. Run the code and give it a try.\n",
+ "The code is pretty straightforward: create a string (`s`) that contains `\"Go Navy\"`, then print out every character in the string. Run the code above and give it a try.\n",
"\n",
"While it works, it does seem a bit wasteful to have repeat `print()` seven times. It would be great if we could automatically generate an arithmetic progression from `0` to `6` and use that to index each character in `s`. Let's start with a plain language description of what we want, then see how that translates into code.\n",
"\n",
"*For every integer from 0 to 6, use that number as an index to print the associated character in the string `s`*.\n",
"\n",
- "The translation to Python is pretty simple. We'll use both the [for() statement](https://docs.python.org/3/tutorial/controlflow.html#tut-for), and the [range() function](https://docs.python.org/3/tutorial/controlflow.html#tut-range) like this:"
+ "The translation to Python is pretty simple. We'll use both the [for()](https://docs.python.org/3/tutorial/controlflow.html#tut-for) statement, and the [range()](https://docs.python.org/3/tutorial/controlflow.html#tut-range) function like this:"
]
},
{
@@ -57,13 +57,13 @@
"source": [
"Important points:\n",
"\n",
- "* The variable `i` can be any legal variable name. In practice, though, it's very common to use `i` when interating over a range of values, so you may see it often.\n",
+ "* The variable `i` can be any legal variable name. In practice, though, it's very common to use `i` when iterating over a range of values, so you may see it often.\n",
"* In line 1 we're iterating over a range starting at `0` and ending at one less than `7`. This is how [range()](https://docs.python.org/3/tutorial/controlflow.html#tut-range) works: it goes from the starting value to one less than the ending value.\n",
- "* Notice that we're indenting code again! This is a very common design pattern in Python, so you should start to feel comfortable with it. It says that everything indented below the line ending in colon (`:`), applies to that line. As an experiment, change the indententation of line 3 so that it lines up with line 2 and re-run the code. What happend?\n",
+ "* Notice that we're indenting code again! This is a very common design pattern in Python, so you should start to feel comfortable with it. It says that everything indented below the line ending in colon (`:`), applies to that line. As an experiment, change the indentation of line 3 so that it lines up with line 2 and re-run the code. What happened?\n",
"\n",
"
\n",
"\n",
- "Here's an example of a [for()](https://docs.python.org/3/tutorial/controlflow.html#tut-for) loop usinf a different variable name and [range()](https://docs.python.org/3/tutorial/controlflow.html#tut-range) starting at a value other than `0`. Predict what gets printed before running the code to check your answer."
+ "Here's an example of a [for()](https://docs.python.org/3/tutorial/controlflow.html#tut-for) loop using a different variable name and [range()](https://docs.python.org/3/tutorial/controlflow.html#tut-range) starting at a value other than `0`. Predict what gets printed before running the code to check your answer."
]
},
{
diff --git a/content/05_iteration01.ipynb b/content/05_iteration01.ipynb
index bb11af3..553732f 100644
--- a/content/05_iteration01.ipynb
+++ b/content/05_iteration01.ipynb
@@ -8,7 +8,7 @@
"\n",
"### `while` Loops\n",
"\n",
- "In addition to [for()](https://docs.python.org/3/tutorial/controlflow.html#tut-for) loops, which iterate over an arithmetic progression, Python offers a way to iterate indefinitely as long as a particular boolen expression remains true. It's called a [while()](https://docs.python.org/3/reference/compound_stmts.html#while) loop. Here's an example:"
+ "In addition to [for()](https://docs.python.org/3/tutorial/controlflow.html#tut-for) loops, which iterate over an arithmetic progression, Python offers a way to iterate indefinitely as long as a particular Boolen expression remains true. It's called a [while()](https://docs.python.org/3/reference/compound_stmts.html#while) loop. Here's an example:"
]
},
{
@@ -30,7 +30,7 @@
"source": [
"
\n",
"\n",
- "If your reaction is: \"*Why is that needed? I could accomplish the same thing with a `for()` loop.*\" then excellent! You're becoming a coder! Try this next example to appreciate how a `while()` loop becomes useful:"
+ "If your reaction is: \"*Why is that needed? I could accomplish the same thing with a `for()` loop.*\" then excellent! You're becoming a coder! Try this next example to appreciate when a [while()](https://docs.python.org/3/reference/compound_stmts.html#while) loop becomes useful:"
]
},
{
@@ -50,7 +50,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "*Note: It's easy to crash the program about by entering something other than an integer. Telling you it's easy to crash a program should immediately make you want to try to do it :-)*"
+ "*Note: It's easy to crash the program above by entering something other than an integer. Telling you it's easy to crash a program should immediately make you want to try to do it :-)*"
]
},
{
@@ -84,7 +84,7 @@
"* We often refer to code written like this as having an *inner* loop and an *outer* loop.\n",
"* The *inner* loop is this one: `for j in range(1,11):`\n",
"* The *outer* loop is this one: `for i in range(1,11):`\n",
- "* Notice that the `range()` function goes from `1` (the starting point) to `10` (one less than the end point)\n",
+ "* Notice that the [range()](https://docs.python.org/3/tutorial/controlflow.html#tut-range) function goes from `1` (the starting point) to `10` (one less than the end point)\n",
"* The indentation is very important!\n",
"\n",
"
\n",
@@ -108,11 +108,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "I'm making use of an important feature in Python called *optional arguments*. We'll explore optional arguments later in the course, but for now it's enough to say that when you call a function (like `print()`), there are things you can pass to the function that are optional. In the case of `print()`, the argument `end = ` is optional. If you don't use it (like all the examples we've seen up to this point), then Python puts a newline after what gets printed. If you specify something using `end = `, then what you specify will be printed (a space in this case) instead of a newline.\n",
+ "I'm making use of an important feature in Python called *optional arguments*. We'll explore optional arguments later in the course, but for now it's enough to say that when you call a function (like [print()](https://docs.python.org/3/library/functions.html)), there are things you can pass to the function that are optional. In the case of [print()](https://docs.python.org/3/library/functions.html), the argument `end = ` is optional. If you don't use it (like all the examples of [print()](https://docs.python.org/3/library/functions.html) we've seen up to this point), then Python puts a newline after what gets printed. If you specify something using `end = `, then what you specify will be printed (a space in this case) instead of a newline.\n",
"\n",
"
\n",
"\n",
- "To really make it pop, let's use Python's `format()` statement (which we discussed in notebook [03_builtinFunctions01.ipynb](./03_builtinFunctions01.ipynb))."
+ "To really make it pop, let's use Python's [format()](https://docs.python.org/3/library/stdtypes.html#str.format) statement (which we discussed in notebook [03_builtinFunctions01.ipynb](./03_builtinFunctions01.ipynb))."
]
},
{
@@ -138,7 +138,7 @@
"* *The break statement, like in C, breaks out of the innermost enclosing for or while loop.*\n",
"* *The continue statement, also borrowed from C, continues with the next iteration of the loop*\n",
"\n",
- "Here's a simple example of using `break()`. It will try to print every number from `1` to `10`, but will stop early if it encounters the number `5`. **NOTE: Before you run the code, think about this question: Do you think it will actually print the number `5` or not? Run the code to check your answer.**"
+ "Here's a simple example of using [break](https://docs.python.org/3/tutorial/controlflow.html#tut-break). It will try to print every number from `1` to `10`, but will stop early if it encounters the number `5`. ***NOTE: Before you run the code, think about this question: Do you think it will actually print the number `5` or not? Run the code to check your answer.***"
]
},
{
@@ -159,7 +159,7 @@
"source": [
"
\n",
"\n",
- "Here's more complex example that determines if an integer is [prime](https://www.mathsisfun.com/definitions/prime-number.html). It uses a `while` loop, an `if` statement, and a `break` statement. There are comments in the code to aid with clarity, which gives you an idea of how to express your thoughts in code comments. Note: I'm using the [modulo operator](https://docs.python.org/3.3/reference/expressions.html#binary) (`%`) to see if one number divides evenly into another number."
+ "Here's a more complex example that determines if an integer is [prime](https://www.mathsisfun.com/definitions/prime-number.html). It uses a [while()](https://docs.python.org/3/reference/compound_stmts.html#while) loop, an [if](https://docs.python.org/3/tutorial/controlflow.html#if-statements) statement, and a [break](https://docs.python.org/3/tutorial/controlflow.html#tut-break) statement. There are comments in the code to aid with clarity, which gives you an idea of how to express your thoughts in code comments. Note: I'm using the [modulo operator](https://docs.python.org/3.3/reference/expressions.html#binary) (`%`) to see if one number divides evenly into another number."
]
},
{
@@ -171,7 +171,7 @@
"# We'll skip the number 2, since it's the only even prime number.\n",
"\n",
"# Check every integer from 2, up to the candidate number. If none of them divides\n",
- "# evenly into the candidate, then its only factors are one and itself; therefor\n",
+ "# evenly into the candidate, then its only factors are one and itself; therefore\n",
"# it's prime. If we find a number that divides evenly into the candidate, then we\n",
"# can quit the loop right away, because we know the candidate is not prime.\n",
"\n",
@@ -181,7 +181,7 @@
"while divisor < n:\n",
" if n % divisor == 0:\n",
" break\n",
- " divisor = divisor + 1\n",
+ " divisor += 1\n",
"\n",
"# if divisor == n, it means we didn't break out of the loop\n",
"if divisor == n:\n",
@@ -197,13 +197,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
+ "*Line 14 is an example of an [augmented assignment statement](https://docs.python.org/3/reference/simple_stmts.html#augassign); a shorthand way of writing `divisor = divisor + 1`.*\n",
+ "\n",
"Prime numbers are a critical part of modern cryptography. It's quite easy to multiply two large prime numbers together (say, `p1` and `p2`) to get a composite number we'll call `C`. However, for really large numbers (think thousands of digits) it's super-hard to start with `C` and figure out the original `p1` and `p2`.\n",
"\n",
- "Our little prime calculator works pretty well, and it's realitively easy to follow, but it's very inefficient. It can tell you a number is **not** prime pretty quickly, but for large numbers it can take a seriously long time to tell you the number is prime. For example, this modest 10-digit prime number takes a couple of minutes to produce a result: `1000000349`.\n",
+ "Our little prime calculator works pretty well, and it's relatively easy to follow, but it's very inefficient. It can tell you a number is **not** prime pretty quickly, but for large numbers it can take a seriously long time to tell you the number is prime. For example, this modest 10-digit prime number takes a couple of minutes to produce a result: `1000000349`.\n",
"\n",
"We can make our calculator much more efficient in a few ways:\n",
"\n",
- "* By only examining divisors up to and including the square root of the candidate, rather than going all the way to the candidate itself. If there's a divisor greater than `sqrt(n)` that goes evenly into `n`, then the result of `n` divided by that divisor would have been discovered somewhere less than or equal to `sqrt(n)`. To use Python's `sqrt()` function, we'll need to import the [math module](https://docs.python.org/3/library/math.html?highlight=sqrt#module-math).\n",
+ "* By only examining divisors up to and including the square root of the candidate, rather than going all the way to the candidate itself. If there's a divisor greater than `sqrt(n)` that goes evenly into `n`, then the result of `n` divided by that divisor would have been discovered somewhere less than or equal to `sqrt(n)`. To use Python's [sqrt()](https://docs.python.org/3/library/math.html#math.sqrt) function, we'll need to import the [math](https://docs.python.org/3/library/math.html?highlight=sqrt#module-math) module.\n",
"\n",
"* We can start by checking if the candidate is an even number (`n % 2 == 0`). If so, we know right away that it can't be prime.\n",
"\n",
@@ -231,7 +233,7 @@
" while divisor <= math.sqrt(n):\n",
" if n % divisor == 0:\n",
" break\n",
- " divisor = divisor + 2\n",
+ " divisor += 2\n",
"\n",
" if divisor > math.sqrt(n):\n",
" print(n,\"is prime.\")\n",
@@ -245,7 +247,7 @@
"source": [
"### `continue`\n",
"\n",
- "The `continue` statement allows you to skip an iteration cycle of a loop and move on to the next one. Here's a simple example:"
+ "The [continue](https://docs.python.org/3/tutorial/controlflow.html#tut-break) statement allows you to skip an iteration cycle of a loop and move on to the next one. Here's a simple example:"
]
},
{
@@ -266,7 +268,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "The code above is quite interesting. It uses [range()](https://docs.python.org/3/library/stdtypes.html#typesseq-range) in a [for()](https://docs.python.org/3/tutorial/controlflow.html#tut-for) loop to iterate over the progression from `1` to `10` and print just the even numbers (*Remember: `range(start,end)` goes from `start` to `end - 1`*). If we encounter an odd number (meaning the remainder of the number divided by `2` is not zero), then we `continue`. That means skipping the `print()` statement in line 6 and going to the next cycle of the loop."
+ "The code above is quite interesting. It uses [range()](https://docs.python.org/3/library/stdtypes.html#typesseq-range) in a [for()](https://docs.python.org/3/tutorial/controlflow.html#tut-for) loop to iterate over the progression from `1` to `10` and print just the even numbers (*Remember: `range(start,end)` goes from `start` to `end - 1`*). If we encounter an odd number (meaning the remainder of the number divided by `2` is not zero), then we [continue](https://docs.python.org/3/tutorial/controlflow.html#tut-break). That means skipping the [print()](https://docs.python.org/3/library/functions.html) statement in line 6 and going to the next cycle of the loop."
]
},
{
diff --git a/content/06_userFunctions00.ipynb b/content/06_userFunctions00.ipynb
index 53768b7..bd2c942 100644
--- a/content/06_userFunctions00.ipynb
+++ b/content/06_userFunctions00.ipynb
@@ -6,7 +6,7 @@
"source": [
"# User Defined Functions\n",
"\n",
- "In section 3 of the jupyter notebooks we explored some of Python's built-in functions. For example, by importing the [math module](https://docs.python.org/3/library/math.html), we can access a range of useful functions, such as factorial:"
+ "In section 3 of the jupyter notebooks we explored some of Python's built-in functions. For example, by importing the [math](https://docs.python.org/3/library/math.html) module, we can access a range of useful functions, such as factorial:"
]
},
{
@@ -17,7 +17,7 @@
"source": [
"import math\n",
"\n",
- "n = 5\n",
+ "n = 8\n",
"fact = math.factorial(n)\n",
"print(fact)"
]
@@ -28,7 +28,7 @@
"source": [
"
\n",
"\n",
- "That's great, but exactly what is a function in Pythona and how do you write your own custom functions?\n",
+ "That's great, but exactly what is a function in Python and how do you write your own custom functions?\n",
"\n",
"Let's start by looking at the equation for a line that you first learned in algebra:\n",
"\n",
@@ -74,11 +74,11 @@
"* We end the function definition with a colon (`:`).\n",
"* More indentation! Everything indented below the function definition is considered part of the function. Lines 4, 5, and 6 are ***not*** part of the function.\n",
"* When Python sees a function definition, it remembers it for later, but doesn't execute the code until the function is called.\n",
- "* We call our function by using its name, followed by parenthesis (line 5). When we call the function, program execution temporatialy transfers to the function until it's complete, then resumes at the next line after the function call.\n",
+ "* We call our function by using its name, followed by parenthesis (line 5). When we call the function, program execution temporarily transfers to the function until it's complete, then resumes at the next line after the function call.\n",
"\n",
"### Arguments, Parameters and Return Values\n",
"\n",
- "*Arguments* are values we pass to our functions; *Parameters* are placeholders within our functions that hold the arguments we pass; *Return Values* are things we want back from our functions when they've completed their calculations. To see this, lets revisit the equation for a line and write a function to calculate a `y` coordiate for a given `x`coordinate:"
+ "*Arguments* are values we pass to our functions; *Parameters* are placeholders within our functions that hold the arguments we pass; *Return Values* are things we want back from our functions when they've completed their calculations. To see this, lets revisit the equation for a line and write a function to calculate a `y` coordinate for a given `x` coordinate:"
]
},
{
@@ -194,7 +194,7 @@
"\n",
"Ugh! How can you keep this straight?\n",
"\n",
- "Don't worry. With practice variable scope will become second nature. In general, programmers will try to structure their code in a modular way to keep variable scope as local as possible. Give each code block everything it needs to do a job and avoid having it reached *outside the box* to do its work. As with any coding technique there are always execeptions, but it's a good rule of thumb.\n",
+ "Don't worry. With practice variable scope will become second nature. In general, programmers will try to structure their code in a modular way to keep variable scope as local as possible. Give each code block everything it needs to do a job and avoid having it reach *outside the box* to do its work. As with any coding technique there are always exceptions, but it's a good rule of thumb.\n",
"\n",
"A major benefit of local variable scope is that you don't have to come up with multiple variable names to do your work. If you focus on variable scope being local, your code can be much cleaner and still be easy to follow. Let's re-write our code for calculating `y` coordinates on a line.\n",
"\n",
@@ -252,7 +252,7 @@
"source": [
"* Notice that I used `x` as both a *parameter* in my function definition (line 3), and as an argument to my function call (line 9). Because the same variable (`x`) has local scope in both the `lineEquation()` function and the main part of the program, Python is able to keep track of them separately.\n",
"* I didn't even use a `y` variable inside my function. I just performed the calculation in-line with the `return` statement.\n",
- "* I also didn't need a `y` variable when I printed the result. I just called the `lineEquation` function in-line with the `print()` statement."
+ "* I also didn't need a `y` variable when I printed the result. I just called the `lineEquation` function in-line with the [print()](https://docs.python.org/3/library/functions.html) statement."
]
},
{
@@ -261,7 +261,7 @@
"source": [
"### Multiple Parameters; Multiple Arguments\n",
"\n",
- "You can have multiple *parameters* and pass multiple *arguments* to functions. Instead of hardcoding it, let's say you wanted the user to enter a value for `x`, the slope (`m`) and the base (`b`). It could look like this:"
+ "You can have multiple *parameters* and pass multiple *arguments* to functions. Instead of hard coding it, let's say you wanted the user to enter a value for `x`, the slope (`m`) and the base (`b`). It could look like this:"
]
},
{
@@ -285,7 +285,7 @@
"source": [
"
\n",
"\n",
- "You can also call functions as you interate. Let's say you wanted to allow the user to compute a series of `y` coordinates over a range of `x` coordinates, with a certain interval. We can't use a [for()](https://docs.python.org/3/tutorial/controlflow.html#tut-for) loop with [range()](https://docs.python.org/3/library/stdtypes.html#typesseq-range), because range() only works with integer types, but we can use a [while()](https://docs.python.org/3/reference/compound_stmts.html#while) loop.\n",
+ "You can also call functions as you iterate, which is very powerful. Let's say you wanted to allow the user to compute a series of `y` coordinates over a range of `x` coordinates, with a certain interval between `x` values. We can't use a [for()](https://docs.python.org/3/tutorial/controlflow.html#tut-for) loop with [range()](https://docs.python.org/3/library/stdtypes.html#typesseq-range), because [range()](https://docs.python.org/3/library/stdtypes.html#typesseq-range) only works with integer types, but we can use a [while()](https://docs.python.org/3/reference/compound_stmts.html#while) loop.\n",
"\n",
"The code is getting more advanced, but you can handle it. Examine the program below. Think about what it does, then run it with these inputs:\n",
"\n",
@@ -313,10 +313,11 @@
"\n",
"print(\"Here are your x,y coordinates:\")\n",
"\n",
- "counter = start\n",
- "while counter <= end:\n",
- " print(\"x = {0:.3f}; y = {1:.3f}\".format(counter,lineEquation(counter,m,b)))\n",
- " counter = counter + interval\n",
+ "x = start\n",
+ "while x <= end:\n",
+ " y = lineEquation(x,m,b)\n",
+ " print(\"x = {0:.3f}; y = {1:.3f}\".format(x,y))\n",
+ " x += interval\n",
"\n",
"print(\"The program is complete.\")"
]
@@ -325,7 +326,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "Do you remember how [format()](https://docs.python.org/3/library/string.html#formatstrings) works in line 14? If you need a refresher, review this notebook again: [03_builtinFunctions01.ipynb](./03_builtinFunctions01.ipynb)"
+ "* Do you remember how [format()](https://docs.python.org/3/library/string.html#formatstrings) works in line 15? If you need a refresher, review this notebook again: [03_builtinFunctions01.ipynb](./03_builtinFunctions01.ipynb)\n",
+ "* Line 16 is an example of an [augmented assignment statement](https://docs.python.org/3/reference/simple_stmts.html#augassign)."
]
},
{
diff --git a/content/07collections00.ipynb b/content/07collections00.ipynb
index c5e208e..deaca0a 100644
--- a/content/07collections00.ipynb
+++ b/content/07collections00.ipynb
@@ -6,7 +6,7 @@
"source": [
"# Lists\n",
"\n",
- "Python [lists](https://docs.python.org/3/library/stdtypes.html#typesseq) are like arrays in other languages. In Python, lists can either be homogenous (every item in the list is the same type) or heterogeneous (a collection of different types), which makes them very powerful. For example, this is a perfectly legal list in Python: `[\"Hello\", 0, 3.141]`. Lists are **iterable**, **mutable** and **ordered** (review these definitions here: [02_operations01.ipynb](./02_operations01.ipynb)). Duplicates are allowed in lists.\n",
+ "Python [lists](https://docs.python.org/3/library/stdtypes.html#typesseq) are like arrays in other languages. In Python, lists can either be homogeneous (every item in the list is the same type) or heterogeneous (a collection of different types), which makes them very powerful. For example, this is a perfectly legal list in Python: `[\"Hello\", 0, 3.141]`. Lists are **iterable**, **mutable** and **ordered** (review these definitions here: [02_operations01.ipynb](./02_operations01.ipynb)). Duplicates are allowed in lists.\n",
"\n",
"*Like any other programming language, there are many ways to approach problems in Python. Two completely different approaches may be equally valid. Keep in mind that as you go through these examples you'll often see multiple ways of doing the same thing. No particular approach is presented here as \"the best\" or \"the only\" way do do things. Find your own unique programming style and embrace it!*\n",
"\n",
@@ -29,7 +29,7 @@
"source": [
"* `L` is just a variable name. You can use any legal variable name to create a list.\n",
"* Each item in a list is separated by a comma, and the list is enclosed in square brackets.\n",
- "* When you use `print()`, Python renders your list as a string to represent it on the screen."
+ "* When you use [print()](https://docs.python.org/3/library/functions.html), Python renders your list as a string to represent it on the screen."
]
},
{
@@ -109,7 +109,7 @@
"metadata": {},
"source": [
"* I'm using Python's [len()](https://docs.python.org/3/library/functions.html) function to determine the number of items in myList.\n",
- "* The loop goes from 0 to len(myList) - 1. That's how [range()](https://docs.python.org/3/tutorial/controlflow.html#tut-range) works."
+ "* The loop goes from `0` to `len(myList) - 1`. That's how [range()](https://docs.python.org/3/tutorial/controlflow.html#tut-range) works."
]
},
{
@@ -164,7 +164,7 @@
"\n",
"You can test if an item is contained in a list using Python's [in](https://docs.python.org/3/reference/expressions.html#membership-test-details) operator.\n",
"\n",
- "Note: In the example below, I'm iterating through a range, with an iteration variable called `_` (underscore). In Python (and many other languages) the use of `_` means: *I don't care about using a specific variable when I iterate, I'm just interested in iterating a certain number of times.*"
+ "Note: In the example below I'm iterating through a range, with an iteration variable called `_` (underscore). In Python (and many other languages) the use of `_` means: *I don't care about using a specific variable when I iterate, I'm just interested in iterating a certain number of times.*"
]
},
{
@@ -218,7 +218,7 @@
"source": [
"
\n",
"\n",
- "If you wanted to modify a copy of a list, but keep the original intact, you can use `copy()`"
+ "If you wanted to modify a copy of a list, but keep the original intact, you can use [copy()](https://docs.python.org/3/tutorial/datastructures.html)."
]
},
{
@@ -280,7 +280,7 @@
"# and lowercase letters to uppercase)\n",
"\n",
"s = input(\"Enter a string:\")\n",
- "L = list(s) # Conver the string into a list of characters\n",
+ "L = list(s) # Convert the string into a list of characters\n",
"print() # Print a blank line for clarity\n",
"print(s)\n",
"print(L)\n",
diff --git a/content/07collections01.ipynb b/content/07collections01.ipynb
index 66eb05f..b2bfbc1 100644
--- a/content/07collections01.ipynb
+++ b/content/07collections01.ipynb
@@ -96,10 +96,10 @@
"source": [
"A few thoughts on dictionaries and copying them:\n",
"\n",
- "* If you assign a value to a dictionary key, and the key is not in the dictionary, Python will add the new *key:value* pair to the dictionary. If the key does exist in the dictionary, Python will replace the current value assigned to the given key with the new value.\n",
- "* You can use the `len()` function on dictionaries to get the number of entries.\n",
- "* You can't copy a dictionary simply by typing `D1 = D2`. Dictionaries are objects, and the variables we use for them are pointers. If you use `D1 = D2`, then `D1` and `D2` will point to the *same* dictionary. You can use the `copy()` method for dictionaries instead.\n",
- "* The `copy()` method performs what's known as a *shallow* copy and works as expected when the values in your dictionary are simple, immutable data types. If your dictionary contains objects as values, then you must perform a *deep* copy using the `deepcopy()` method. This applies to sets and lists as well. See the Additional Resources section below for more information."
+ "* If you assign a value to a dictionary with a given key, and the key is not already in the dictionary, Python will add the new *key:value* pair to the dictionary. If the key does exist in the dictionary, Python will replace the current value assigned to the given key with the new value.\n",
+ "* You can use the [len()](https://docs.python.org/3/library/functions.html) function on dictionaries to get the number of entries.\n",
+ "* You can't copy a dictionary simply by typing `D1 = D2`. Dictionaries are objects, and the variables we use for them are pointers. If you use `D1 = D2`, then `D1` and `D2` will point to the *same* dictionary. You can use the [copy()](https://docs.python.org/3/library/copy.html) method for dictionaries instead.\n",
+ "* The [copy()](https://docs.python.org/3/library/copy.html) method performs what's known as a *shallow* copy and works as expected when the values in your dictionary are simple, immutable data types. If your dictionary contains objects as values, then you must perform a *deep* copy using the [deepcopy()](https://docs.python.org/3/library/copy.html) method. This applies to sets and lists as well. See the Additional Resources section below for more information."
]
},
{
@@ -126,9 +126,9 @@
"
\n",
"
\n",
"\n",
- "Below is a coding example. Notice how I start with an empty dictionary (`D1`), then I add key value pairs one at a time. The keys in our dictionary are integers and the values are strings.\n",
+ "Below is a coding example. Notice how I start with an empty dictionary (`D1`), then I add key value pairs one at a time. Both the keys and values in our dictionary are strings.\n",
"\n",
- "Run the code and trace the output. Convience yourself you can follow what's happening. Change the code and try some different operations."
+ "Run the code and trace the output. Convince yourself you can follow what's happening. Change the code and try some different operations."
]
},
{
@@ -138,27 +138,28 @@
"outputs": [],
"source": [
"D1 = {}\n",
- "D1[1] = \"Number 1\"\n",
- "D1[2] = \"Number 2\"\n",
- "D1[3] = \"Number 3\"\n",
+ "D1['k1'] = \"Number 1\"\n",
+ "D1['k2'] = \"Number 2\"\n",
+ "D1['k3'] = \"Number 3\"\n",
"\n",
"print(D1)\n",
- "D1[2] = \"Number two\"\n",
+ "D1['k2'] = \"Number two\"\n",
"print(D1)\n",
"\n",
"print(\"The number of entries in D1 =\",len(D1))\n",
"\n",
- "# Does not make a copy, changing D2 will affect D1\n",
+ "# Does not make a separate copy, changing D2 will affect D1\n",
"print(\"\\nIncorrect copy\")\n",
"D2 = D1\n",
- "D2[2] = \"Number two\"\n",
+ "D2['k2'] = \"Go Navy!\"\n",
"print(D1)\n",
"print(D2)\n",
"\n",
- "# Makes a shallow copy, changing D2 will not affect D1\n",
+ "# Makes a separate copy, changing D2 will not affect D1\n",
"print(\"\\nCorrect, shallow copy\")\n",
"D2 = D1.copy()\n",
- "D2[3] = \"Number three\"\n",
+ "D2['k3'] = \"Beat Army!\"\n",
+ "D2['k4'] = \"Python is awesome!\"\n",
"print(D1)\n",
"print(D2)"
]
diff --git a/content/07collections02.ipynb b/content/07collections02.ipynb
index 7195383..ece9283 100644
--- a/content/07collections02.ipynb
+++ b/content/07collections02.ipynb
@@ -79,7 +79,7 @@
"source": [
"strInput = input(\"Enter a string:\")\n",
"\n",
- "S = set(strInput) # Cast the string to a set. It will toss duplicate letters.\n",
+ "S = set(strInput) # Cast the string to a set. It will remove duplicate letters.\n",
"\n",
"print(\"There are {0:d} unique characters in your string.\".format(len(S)))\n",
"\n",
@@ -221,31 +221,14 @@
"source": [
"
\n",
"\n",
- "Here's an example of many different set operations. Run the code and conveince yourself you can follow what's happening."
+ "Here's an example of many different set operations. Run the code and conveince yourself you can follow what's happening. Refer to the set operations above."
]
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "S1 {1, 2, 3, 4, 5}\n",
- "S2 {3, 4, 5, 6, 7}\n",
- "S3 {3, 4}\n",
- "\n",
- "S1 - S2 {1, 2}\n",
- "S1 & S2 {3, 4, 5}\n",
- "S3 <= S2 True\n",
- "S2 >= S1 False\n",
- "S1 ^ S2 {1, 2, 6, 7}\n",
- "S1 | S2 {1, 2, 3, 4, 5, 6, 7}\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"S1 = {1,2,3,4,5}\n",
"S2 = {3,4,5,6,7}\n",
diff --git a/content/07collections03.ipynb b/content/07collections03.ipynb
index 603b868..eba2712 100644
--- a/content/07collections03.ipynb
+++ b/content/07collections03.ipynb
@@ -6,7 +6,7 @@
"source": [
"# Tuples\n",
"\n",
- "A [tuple](https://docs.python.org/3/library/stdtypes.html#typesseq) is an immutable sequence type of Python objects. They're frequently used when you want to return more than one value from a function. Python tuples can be heterogeneous, which makes them very powerful. For example, this is a perfectly legal set in Python: `{\"Hello\", 0, 3.141}`. Tuples are **iterable**, **immumutable** and **ordered**. Duplicates are allowed in tuples.\n",
+ "A [tuple](https://docs.python.org/3/library/stdtypes.html#typesseq) is an immutable sequence type of Python objects. They're frequently used when you want to return more than one value from a function. Python tuples can be heterogeneous, which makes them very powerful. For example, this is a perfectly legal tuple in Python: `(\"Hello\", 0, 3.141)`. Tuples are **iterable**, **immutable** and **ordered**. Duplicates are allowed in tuples.\n",
"\n",
"Let's start with a simple example, then discuss how tuples are useful for returning more than one value from a function."
]
@@ -30,8 +30,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "* Notice that tuples are described with parenthesis, rather than brackets which describe lists.\n",
- "* Even though you create a tuple with paraenthesis, you access individual elements with brackets (e.g. line 4)\n",
+ "* Notice that tuples are described with parenthesis, rather than brackets which describe lists `[]` or braces that describe sets `{}`.\n",
+ "* Even though you create a tuple with parenthesis, you access individual elements with brackets (e.g. line 4)\n",
"* The loop uses `t` (lowercase) as a variable to iterate over the tuple `T` (uppercase)\n",
"\n",
"
\n",
@@ -159,7 +159,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "The program above doesn't work. It's a good framework, but it won't run. What do we return? How would you modify the code using tuples so that you could return both the sum of the odd numbers and the sum of the even numbers, using a single `return` statement?"
+ "The program above doesn't work. It's a good template, but it won't run. What do we return? How would you modify the code using tuples so that you could return both the sum of the odd numbers and the sum of the even numbers, using a single `return` statement?"
]
},
{
diff --git a/content/07collections04.ipynb b/content/07collections04.ipynb
index 4a403e3..b71679c 100644
--- a/content/07collections04.ipynb
+++ b/content/07collections04.ipynb
@@ -125,7 +125,7 @@
"\n",
"
\n",
"\n",
- "Now let's use Python's `id()` function to examine the unique id numbers of the variables being used:"
+ "Now let's use Python's [id()](https://docs.python.org/3/library/functions.html) function to examine the unique id numbers of the variables being used:"
]
},
{
@@ -141,7 +141,7 @@
"n = int(input(\"Enter an integer: \"))\n",
"print(\"Outside function before call: n = {0:,d}; id(n) = {1:d}\".format(n,id(n)))\n",
"print(\"2 x {0:,d} = {1:,d}\".format(n,doubleIt(n)))\n",
- "print(\"Outside funciton after call: n = {0:,d}; id(n) = {1:d}\".format(n,id(n)))"
+ "print(\"Outside function after call: n = {0:,d}; id(n) = {1:d}\".format(n,id(n)))"
]
},
{
@@ -182,20 +182,9 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Outside function before call: L = [2, 4, 6]; id(L) = 140035665549632\n",
- "Inside function before mod: aList = [2, 4, 6]; id(aList) = 140035665549632\n",
- "Inside function after mod: aList = [2, 100, 6]; id(aList) = 140035665549632\n",
- "Outside function before call: L = [2, 100, 6]; id(L) = 140035665549632\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"def modifySecond(aList):\n",
" print(\"Inside function before mod: aList = {0:s}; id(aList) = {1:d}\".format(str(aList),id(aList)))\n",
@@ -216,7 +205,7 @@
"Lots going on here:\n",
"\n",
"* I'm making use of Python's [str()](https://docs.python.org/3/library/stdtypes.html#str) function which takes a variable a provides a string representation of it. Very handy when using formatted printing for a list.\n",
- "* Notice that I use a single `return` at the end of my function, with nothing after it. Using return all by itself means I'm acutally returning a special pointer called [None](https://docs.python.org/3/library/constants.html#None). You could leave the `return` statement off all together and it would still work, but it enhances your code's clarity to delinate the end of your function with a solitary `return` statement.\n",
+ "* Notice that I use a single `return` at the end of my function, with nothing after it. Using return all by itself means I'm actually returning a special pointer called [None](https://docs.python.org/3/library/constants.html#None). You could leave the `return` statement off all together and it would still work, but it enhances your code's clarity to delineate the end of your function with a solitary `return` statement.\n",
"* The id (Pointer) of our list never changes. It's the same outside the function as well as inside.\n",
"* Since Python lists are mutable, any changes we make to the parameter `aList` (inside the function) will impact the argument `L` (outside the function).\n",
"\n",
diff --git a/content/09_hashing00.ipynb b/content/09_hashing00.ipynb
index 85d74cf..a648c08 100644
--- a/content/09_hashing00.ipynb
+++ b/content/09_hashing00.ipynb
@@ -6,13 +6,13 @@
"source": [
"# Hashing Strings in Python\n",
"\n",
- "As a quick review, hash functions are one-way functions with the following properties:\n",
+ "As a quick review from your Plebe Cyber Course, hash functions are one-way functions with the following properties:\n",
"\n",
"1. Easy (for a computer) to compute the hash for a string\n",
"2. Hard (takes way too long) to start with a hash value and construct a string that hashes to it\n",
"3. Impossible to start with a string and find a different string that hashes to the same value -- ideal hash functions produce unique keys\n",
"\n",
- "
\n",
+ "
\n",
"
\n",
"
\n",
"\n",
@@ -20,7 +20,7 @@
"\n",
"1. Select the algorithm (digest) to use for hashing\n",
"2. Encode the string as a series of bytes\n",
- "3. Hash the encoded string and convert the result to a human-readable hexidecimal representation"
+ "3. Hash the encoded string and convert the result to a human-readable hexadecimal representation"
]
},
{
@@ -31,7 +31,7 @@
"\n",
"*The pros / cons and technical details of various hashing algorithms are beyond the scope of this course.*\n",
"\n",
- "You can display the algorithms available on your system using the `algorithms_available` method. This method lists all the algorithms available in your system, including the ones available in the Python distribution as well as those in the `OpenSSl` package. To use a hashing function, start by importing the [hashlib](https://docs.python.org/3/library/hashlib.html) library within your code."
+ "You can display the algorithms available on your system using the `algorithms_available` constant attribute. This constant lists all the algorithms available in your system, including the ones available in the Python distribution as well as those in the `OpenSSl` package. To use a hashing function, start by importing the [hashlib](https://docs.python.org/3/library/hashlib.html) library within your code."
]
},
{
@@ -113,24 +113,9 @@
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "name": "stdin",
- "output_type": "stream",
- "text": [
- "Enter a string: Go Navy\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "The sha1 hash of \"Go Navy\" is 6a2ca3269b5ffb07bf7092757669f83575510540\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"import hashlib\n",
"\n",
diff --git a/content/10_exceptions.ipynb b/content/10_exceptions.ipynb
index b306f1a..6f7bd26 100644
--- a/content/10_exceptions.ipynb
+++ b/content/10_exceptions.ipynb
@@ -110,7 +110,7 @@
"source": [
"### 1. Make exceptions specific\n",
"\n",
- "In the example above, we're dealing with one specific exception `ValueError`. Recall that Python's `input` function always returns a string type and if we try to cast the string \"42\" to an int, it works fine. If we try to cast the string \"Navy\" to an int, a `ValueError` exception is raised. If we left the `ValueError` qualifier off our `except` clause, the code would still work, however we wouldn't able to determine exactly what cause the error or take specific actions based on specific errors. To cover multiple exceptions, Python allows you to chain multiple `except` clauses within a single `try...except`. Run the example below for a demonstration."
+ "In the example above, we're dealing with one specific exception `ValueError`. Recall that Python's [input()](https://docs.python.org/3/library/functions.html) function always returns a string type and if we try to cast the string \"42\" to an int, it works fine. If we try to cast the string \"Navy\" to an int, a `ValueError` exception is raised. If we left the `ValueError` qualifier off our `except` clause, the code would still work, however we wouldn't able to determine exactly what cause the error or take specific actions based on specific errors. To cover multiple exceptions, Python allows you to chain multiple `except` clauses within a single `try...except`. Run the example below for a demonstration."
]
},
{
@@ -143,17 +143,6 @@
"Exception handling should only be used for situations that would cause run time errors. Consider (and run) the example below. Not finding the desired sub-string is not a run time error, but trying to index beyond the end of the string is."
]
},
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "
\n",
- "
\n",
- "
\n",
- "\n",
- "Why will the `IndexError` exception be raised in the code below?"
- ]
- },
{
"cell_type": "code",
"execution_count": null,
@@ -186,19 +175,32 @@
"metadata": {},
"outputs": [],
"source": [
- "while (1): \n",
+ "while (True):\n",
+ " \n",
" try:\n",
" n = int(input(\"Enter an integer between 1 and 10: \"))\n",
" if (n < 1) or (n > 10):\n",
" print(\"Input not between 1 and 10. Please try again\")\n",
" else:\n",
" break\n",
+ " \n",
" except ValueError:\n",
" print(\"Invalid integer format. Please try again.\")\n",
" \n",
"print(\"You entered:\",n)"
]
},
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "
\n",
+ "
\n",
+ "
\n",
+ "\n",
+ "line 1 (`while(True)`) should cause the program above to loop forever. However, the program behaves as intended, and quits if a number is entered that is between 1 and 10. Why?"
+ ]
+ },
{
"cell_type": "markdown",
"metadata": {},
diff --git a/content/11_recursion.ipynb b/content/11_recursion.ipynb
index 675b51a..5bdb7f2 100644
--- a/content/11_recursion.ipynb
+++ b/content/11_recursion.ipynb
@@ -24,7 +24,7 @@
" return total\n",
"\n",
"def main():\n",
- " n = int(input(\"Enter an integer: \"))\n",
+ " n = int(input(\"Enter a positive integer >= 1: \"))\n",
" print(\"The sum of integers from 1 to {0:d} is {1:,d}\".format(n,sumInts(n)))\n",
" return\n",
" \n",
@@ -52,7 +52,7 @@
"\n",
"This collection of *Stack Frames* is known as the *Call Stack*. Think of it like a stack of plates, where the one on top is the only one that's running, and all the plates below are waiting for their turn. The plates are arranged in Last-In-First-Out (LIFO) order and the picture looks something like this (start at the bottom right):\n",
"\n",
- "
\n",
+ "
\n",
"
\n",
"
\n"
]
@@ -63,7 +63,7 @@
"source": [
"## Recursion and Stack Frames\n",
"\n",
- "Recursion in a programming language is simply the process of having a function call itself. Just like in the example above, every time a function is called, even if it's calling itself, another *Frame* is generated on the *Call Stack*. Below is the same program written recursively. Try it with a few integers below 1000. Then try 10000. What happens?"
+ "Recursion in a programming language is the process of having a function call itself. Just like in the example above, every time a function is called, even if it's calling itself, another *Frame* is generated on the *Call Stack*. Below is the same program written recursively. Try it with a few integers below 1000. Then try 10000. What happens?"
]
},
{
@@ -79,7 +79,7 @@
" return n + sumInts(n-1)\n",
"\n",
"def main():\n",
- " n = int(input(\"Enter an integer: \"))\n",
+ " n = int(input(\"Enter a positive integer >= 1: \"))\n",
" print(\"The sum of integers from 1 to {0:d} is {1:,d}\".format(n,sumInts(n)))\n",
" return\n",
" \n",
@@ -94,9 +94,9 @@
"source": [
"# If there are limits on how deep recursion can go, why do we use it?\n",
"\n",
- "While there can be a speed and resource penalty when using recursion, there are many computing problems that can be greatly simplified when implemented recursively. We'll talk about recursion and runtime performance in later courses.\n",
+ "While there can be a speed and resource penalty when using recursion, there are many computing problems that can be greatly simplified when implemented recursively. We'll talk about recursion and run time performance in later courses.\n",
"\n",
- "For now, it's your turn. Finish the code below to implement a function (`reverseIt()`) that uses recursion to take a given string and return it in reverse order. For example: `reverseIt('Navy!')` would be `'!yvaN'`."
+ "For now, it's your turn. Finish the code below to implement a function (`reverseIt()`) that uses recursion to take a given string and return it in reverse order. For example: `reverseIt('Navy!')` would return `'!yvaN'`."
]
},
{
@@ -107,11 +107,6 @@
"source": [
"def reverseIt(s):\n",
" # Write your code here.\n",
- " # Remove this solution from the student version.\n",
- " if len(s) == 1:\n",
- " return s\n",
- " else:\n",
- " return s[-1] + reverseIt(s[:-1])\n",
"\n",
"def main():\n",
" s = input(\"Enter a string: \")\n",
diff --git a/content/12_oop.ipynb b/content/12_oop.ipynb
index daba157..9e412a8 100644
--- a/content/12_oop.ipynb
+++ b/content/12_oop.ipynb
@@ -22,7 +22,8 @@
"outputs": [],
"source": [
"L = [3,2,1] # L (the object) is an instance of the List class\n",
- "L.sort() # Invoking the sort() method on object L\n",
+ "print(L)\n",
+ "L.sort() # Invoking the sort() method on object L\n",
"print(L)"
]
},
@@ -42,9 +43,11 @@
"outputs": [],
"source": [
"class Midshipman:\n",
- " alpha = 201234\n",
+ " alpha = 222234\n",
" company = 13\n",
- " \n",
+ "\n",
+ "# --------------------------\n",
+ "\n",
"mid1 = Midshipman()\n",
"mid2 = Midshipman()\n",
"\n",
@@ -56,14 +59,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "In the example above, we're accessing the properties of the class directly using \"dot notation\". In lines 8 and 9, we print the `alpha` and `company` properties of the `mid1` and `mid2` objects by using the object name, followed by a dot (\".\"), followed by the name of the property we want to access, e.g. `mid1.alpha`. We'll seen an example later in this notebook where dot notation can lead to some problems."
+ "In the example above, we're accessing the properties of the class directly using \"dot notation\". In lines 10 and 11, we print the `alpha` and `company` properties of the `mid1` and `mid2` objects by using the object name, followed by a dot (\".\"), followed by the name of the property we want to access, e.g. `mid1.alpha`. We'll seen an example later in this notebook where directly accessing properties using dot notation can lead to some problems."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "## So Every Instance Of A Class Has The Same Values?"
+ "## So Every Instance Of A Class Has The Same Property Values?"
]
},
{
@@ -85,8 +88,10 @@
" self.alpha = alpha\n",
" self.company = company\n",
" \n",
- "mid1 = Midshipman(201234,13)\n",
- "mid2 = Midshipman(209999,8)\n",
+ "# --------------------------\n",
+ " \n",
+ "mid1 = Midshipman(221234,13)\n",
+ "mid2 = Midshipman(229999,8)\n",
"\n",
"print(mid1.alpha,mid1.company)\n",
"print(mid2.alpha,mid2.company)"
@@ -137,10 +142,12 @@
" else:\n",
" reg = \"Second\"\n",
" return reg\n",
+ " \n",
+ "# --------------------------\n",
"\n",
- "mid1 = Midshipman(201234,13)\n",
+ "mid1 = Midshipman(221234,13)\n",
"print(mid1.regiment())\n",
- "mid2 = Midshipman(209999,22)\n",
+ "mid2 = Midshipman(229999,22)\n",
"print(mid2.regiment())"
]
},
@@ -168,8 +175,10 @@
" \n",
" def prtBonus(self,additionalPoints):\n",
" self.prtScore += additionalPoints\n",
+ " \n",
+ "# --------------------------\n",
" \n",
- "mid1 = Midshipman(201234,13,81)\n",
+ "mid1 = Midshipman(221234,13,81)\n",
"print(mid1.prtScore)\n",
"mid1.prtBonus(7)\n",
"print(mid1.prtScore)"
@@ -200,7 +209,9 @@
" \n",
" def area(self):\n",
" return math.pi * self.radius**2\n",
- " \n",
+ "\n",
+ "# --------------------------\n",
+ "\n",
"c1 = Circle(5)\n",
"print(c1.area())"
]
@@ -211,7 +222,7 @@
"source": [
"Pretty straightforward, right? It calculates and prints the area of a circle with radius 5.\n",
"\n",
- "Now change line 11 above to read: `c1 = Circle(-1)` and re-run the code. It doesn't crash, but is the answer correct? Is -1 a valid value for the radius of a circle? What if you changed line 11 to read: `c1 = Circle(\"NAVY\")` and re-run the code again? What happens now?\n",
+ "Now change line 13 above to read: `c1 = Circle(-1)` and re-run the code. It doesn't crash, but is the answer correct? Is -1 a valid value for the radius of a circle? What if you changed line 13 to read: `c1 = Circle(\"NAVY\")` and re-run the code again? What happens now?\n",
"\n",
"Making properties private and controlling access to them though *getter* and *setter* methods allows you (the programmer) to perform data validation and establish default values for properties when invalid entries are received. To designate a property as private, precede its name with two underscore characters (`__`). Examine and run the updated code for our circle class below. Ensure you can explain everything that's happening."
]
@@ -240,6 +251,8 @@
" self.__radius = radius\n",
" else:\n",
" self.__radius = 0\n",
+ " \n",
+ "# --------------------------\n",
"\n",
"c1 = Circle(5)\n",
"print(c1.getRadius())\n",
@@ -287,6 +300,8 @@
" def average(self):\n",
" # Computes the average of all the scores in the hwScores (list) property.\n",
" # Returns: hwAverage\n",
+ "\n",
+ "# --------------------------\n",
" \n",
"# Write a program here that creates a new CyberStudent object.\n",
"# Add three homework grades of your choosing (integers) to the student's record. Note: You should have designed average to compute the average\n",
diff --git a/content/13_bigO.ipynb b/content/13_bigO.ipynb
index 5a12fa7..2c0672c 100644
--- a/content/13_bigO.ipynb
+++ b/content/13_bigO.ipynb
@@ -8,7 +8,7 @@
"\n",
"Here's a little code demo that may help reinforce Big-O.\n",
"\n",
- "As discussed in the class notes, we're seeking to quantify an order of magnitude when describing runtime performance. If two competing algorithms operating on big complex problems finish within a few seconds or microseconds of each other, then we'd say they both have the same runtime performance (Big-O). What we're talking about is: one algorithm takes seconds or minutes, and the other takes days or longer.\n",
+ "We're seeking to quantify an order of magnitude when describing run time performance. If two competing algorithms operating on big complex problems finish within a few seconds or microseconds of each other, then we'd say they both have the same run time performance (Big-O). What we're talking about is: one algorithm takes seconds or minutes, and the other takes days or longer.\n",
"\n",
"The code below reads an integer (`n`) from the user and forks a child process. In the child, the product of `n` * `n` is calculated through straight multiplication. In the parent, the product of `n` * `n` is calculated in a loop using repeated addition. They both come up with the same answer, so which one is better? The answer depends on how big `n` is.\n",
"\n",
@@ -18,7 +18,7 @@
"\n",
"2. The process (parent or child) with the shortest elapsed time should finish first. The elapsed time display is in the form: `H:MM:SS.Micro Seconds`. The caveat here is that without some kind of process synchronization or inter-process communication, there's technically no guarantee that the child process will print its display first when using very small integer values. When you're talking about microsecond timing, the scheduler could get bogged down with other processes and the parent may actually display its results first, even though it has a longer elapsed time. There's actually another reason why you'll see the parent process finish first (see number 3 below).\n",
"\n",
- "3. You should notice that for small-ish integer inputs (let's say up to about `100000`), the parent completes its calculation first. Multiplication in a microprocessor is more complex than addition. As Computer Scientists like to say: it's *expensive*. Assuming that multiplication is one step (as discussed in the class notes), we would classify the child process as running in constant time `O(1)` and the parent process as running in `O(n)` time. No matter how big the input is, multiplication always finishes in roughly the same time (even if it loses to repeated addition for smaller inputs); however as the size of the input grows, the runtime performance of repeated addition gets worse (grows linearly), because it's proportional to the size of the input.\n",
+ "3. You should notice that for small-ish integer inputs (let's say up to about `100000`), the parent completes its calculation first. Multiplication in a microprocessor is more complex than addition. As Computer Scientists like to say: it's *expensive*. Assuming that multiplication is one step (as discussed in the class notes), we would classify the child process as running in constant time `O(1)` and the parent process as running in `O(n)` time. No matter how big the input is, multiplication always finishes in roughly the same time (even if it loses to repeated addition for smaller inputs); however as the size of the input grows, the run time performance of repeated addition gets worse (grows linearly), because it's proportional to the size of the input.\n",
"\n",
"Run the code a few times with different inputs and see what happens. What if you enter `1`? How about `1000`? How about `10000`? Try 1 followed by 8 zeros. On my machine that took the child process about .04 seconds and the parent process about 11.5 seconds. Where's the crossover when multiplication runs in less time than repeated addition? What if you try a really, really big input and let it run overnight?\n",
"\n",
@@ -29,31 +29,9 @@
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "name": "stdin",
- "output_type": "stream",
- "text": [
- "Enter a positive integer greater than 0: 36475876\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "\n",
- "Child pid = 4413\n",
- "Elapsed time: 0:00:00.108903\n",
- "1,330,489,529,967,376\n",
- "\n",
- "Parent pid = 4302\n",
- "Elapsed time: 0:00:13.981482\n",
- "1,330,489,529,967,376\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"import os\n",
"from datetime import datetime\n",
@@ -126,7 +104,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.9"
+ "version": "3.8.2"
}
},
"nbformat": 4,
diff --git a/content/13_codeTemplate.ipynb b/content/13_codeTemplate.ipynb
index 7a8b0ba..25b73be 100644
--- a/content/13_codeTemplate.ipynb
+++ b/content/13_codeTemplate.ipynb
@@ -18,7 +18,7 @@
"\n",
"The rest of the template may be adjusted or omitted as necessary, depending on the structure of your program. Make liberal use of in-line comments throughout your code to describe its function. Also make effective use of spacing and separators to give your code a clean, consistent, easy-to-read look.\n",
"\n",
- "The code below will actually run. Click on it and type `Cntl-Enter`."
+ "The code below will actually run."
]
},
{
diff --git a/content/13_fibonacci.ipynb b/content/13_fibonacci.ipynb
index 9450bad..b710dbb 100644
--- a/content/13_fibonacci.ipynb
+++ b/content/13_fibonacci.ipynb
@@ -53,7 +53,7 @@
"\n",
"Before we write the generalized recurrence relation, let's take a look at how the algorithm behaves for a few iterations:\n",
"\n",
- "
\n",
+ "
\n",
"
\n",
"\n",
"So how would we write the generalized relation for the worst case scenario? Well, let's start with this:\n",
@@ -88,7 +88,7 @@
"source": [
"## Non-recursive Fibonacci\n",
"\n",
- "Here's some code to calculate the Fibonacci Sequence iteratively (without recursion). What is the Big-O runtime performance of this algorithm? Is it better than the recursive version?"
+ "Here's some code to calculate the Fibonacci Sequence iteratively (without recursion). What is the Big-O run time performance of this algorithm? Is it better than the recursive version?"
]
},
{
@@ -162,7 +162,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.9"
+ "version": "3.8.2"
}
},
"nbformat": 4,
diff --git a/images/03formatSpecifier.png b/images/03formatSpecifier.png
new file mode 100644
index 0000000..c347c09
Binary files /dev/null and b/images/03formatSpecifier.png differ
diff --git a/images/03complexExpression.png b/images/04complexExpression.png
similarity index 100%
rename from images/03complexExpression.png
rename to images/04complexExpression.png
diff --git a/images/03if-else-elifstatement.png b/images/04if-else-elifstatement.png
similarity index 100%
rename from images/03if-else-elifstatement.png
rename to images/04if-else-elifstatement.png
diff --git a/images/03simpleExpression.png b/images/04simpleExpression.png
similarity index 100%
rename from images/03simpleExpression.png
rename to images/04simpleExpression.png
diff --git a/images/08hashing.png b/images/09hashing.png
similarity index 100%
rename from images/08hashing.png
rename to images/09hashing.png
diff --git a/images/10stackframes.png b/images/11stackframes.png
similarity index 100%
rename from images/10stackframes.png
rename to images/11stackframes.png
diff --git a/images/fibonacci.png b/images/13fibonacci.png
similarity index 100%
rename from images/fibonacci.png
rename to images/13fibonacci.png