From 8b01fa24b80ccfe5fc25538ec2ac97c72fc3b12d Mon Sep 17 00:00:00 2001 From: David Beazley Date: Tue, 2 Jun 2020 06:20:01 -0500 Subject: [PATCH 01/89] Fix typo --- Notes/02_Working_with_data/01_Datatypes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/02_Working_with_data/01_Datatypes.md b/Notes/02_Working_with_data/01_Datatypes.md index 7d42dfd1c..9a038de7f 100644 --- a/Notes/02_Working_with_data/01_Datatypes.md +++ b/Notes/02_Working_with_data/01_Datatypes.md @@ -52,7 +52,7 @@ Example: s = ('GOOG', 100, 490.1) ``` -Sometimes the `()` are ommitted in the syntax. +Sometimes the `()` are omitted in the syntax. ```python s = 'GOOG', 100, 490.1 From 37290ea977f59b4b335f27c69cd84119b5a6df70 Mon Sep 17 00:00:00 2001 From: zyuhel Date: Wed, 3 Jun 2020 01:47:50 +0300 Subject: [PATCH 02/89] typo fix --- Notes/02_Working_with_data/07_Objects.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/02_Working_with_data/07_Objects.md b/Notes/02_Working_with_data/07_Objects.md index c357f414d..cf20193ff 100644 --- a/Notes/02_Working_with_data/07_Objects.md +++ b/Notes/02_Working_with_data/07_Objects.md @@ -238,7 +238,7 @@ items[1].sqrt(2) # math except items[2]: # ValueError ``` -With great power come responsibility. Just because you can do that doesn't me you should. +With great power come responsibility. Just because you can do that doesn't mean you should. ## Exercises From e5cc209025ff80b2b303f050a5c95ffd3fa2aafe Mon Sep 17 00:00:00 2001 From: David Beazley Date: Tue, 2 Jun 2020 19:57:05 -0500 Subject: [PATCH 03/89] Fix typo --- Notes/02_Working_with_data/06_List_comprehension.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/02_Working_with_data/06_List_comprehension.md b/Notes/02_Working_with_data/06_List_comprehension.md index 18a32295c..11e5ae9e3 100644 --- a/Notes/02_Working_with_data/06_List_comprehension.md +++ b/Notes/02_Working_with_data/06_List_comprehension.md @@ -80,7 +80,7 @@ for variable_name in sequence: ### Historical Digression -List comprehension come from math (set-builder notation). +List comprehensions come from math (set-builder notation). ```code a = [ x * x for x in s if x > 0 ] # Python From dd47473fd47b6b8219b0bd329ae4ce64941a67c0 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 3 Jun 2020 09:24:03 +0200 Subject: [PATCH 04/89] Fix typo in Introduction/Numbers --- Notes/01_Introduction/03_Numbers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/01_Introduction/03_Numbers.md b/Notes/01_Introduction/03_Numbers.md index eb6db46a8..d725fc48f 100644 --- a/Notes/01_Introduction/03_Numbers.md +++ b/Notes/01_Introduction/03_Numbers.md @@ -242,7 +242,7 @@ Months 309 ### Exercise 1.11: Bonus -While you’re at it, fix the program to correct the for overpayment that occurs in the last month. +While you’re at it, fix the program to correct for the overpayment that occurs in the last month. ### Exercise 1.12: A Mystery From 6f7e99028e48ebbfbffdb1283638c72eb0332a9b Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 3 Jun 2020 10:43:06 +0200 Subject: [PATCH 05/89] Remove misplaced prompt in Introduction/Lists --- Notes/01_Introduction/05_Lists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/01_Introduction/05_Lists.md b/Notes/01_Introduction/05_Lists.md index b235b9ddf..d9ae0ca7f 100644 --- a/Notes/01_Introduction/05_Lists.md +++ b/Notes/01_Introduction/05_Lists.md @@ -157,7 +157,7 @@ t = sorted(s) # s unchanged, t holds sorted values >>> nums * 2 [1, 2, 3, 4, 5, 1, 2, 3, 4, 5] >>> nums + [10, 11, 12, 13, 14] -[1, 2, 3, 4, 5, 10, 11, 12, 13, 14] >>> +[1, 2, 3, 4, 5, 10, 11, 12, 13, 14] ``` Specifically, lists don't represent vectors/matrices as in MATLAB, Octave, R, etc. From 1fbe7e6ef119e054acebb2fc8195a9b54aa669c5 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 3 Jun 2020 11:24:42 +0200 Subject: [PATCH 06/89] Fix typo in Working with data/Containers --- Notes/02_Working_with_data/02_Containers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/02_Working_with_data/02_Containers.md b/Notes/02_Working_with_data/02_Containers.md index c3b53731a..a8b79f1d4 100644 --- a/Notes/02_Working_with_data/02_Containers.md +++ b/Notes/02_Working_with_data/02_Containers.md @@ -335,7 +335,7 @@ accessed by key names instead of numeric column numbers. This is often preferred because the resulting code is easier to read later. Viewing large dictionaries and lists can be messy. To clean up the -output for debugging, considering using the `pprint` function. +output for debugging, consider using the `pprint` function. ```python >>> from pprint import pprint From 36d4382f86667e8760e1c6659153b1d1a4aa26e3 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 3 Jun 2020 11:35:10 +0200 Subject: [PATCH 07/89] Split run-in line in Working_with_data/Formatting --- Notes/02_Working_with_data/03_Formatting.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Notes/02_Working_with_data/03_Formatting.md b/Notes/02_Working_with_data/03_Formatting.md index 01e4d6818..ae88c83b3 100644 --- a/Notes/02_Working_with_data/03_Formatting.md +++ b/Notes/02_Working_with_data/03_Formatting.md @@ -58,7 +58,8 @@ Common modifiers adjust the field width and decimal precision. This is a partia ```code :>10d Integer right aligned in 10-character field :<10d Integer left aligned in 10-character field -:^10d Integer centered in 10-character field :0.2f Float with 2 digit precision +:^10d Integer centered in 10-character field +:0.2f Float with 2 digit precision ``` ### Dictionary Formatting From 7578acae9f0b7a078793840c88f70437bb7a0d9a Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 3 Jun 2020 11:48:45 +0200 Subject: [PATCH 08/89] Separate output from commands in Working with data/Sequences --- Notes/02_Working_with_data/04_Sequences.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Notes/02_Working_with_data/04_Sequences.md b/Notes/02_Working_with_data/04_Sequences.md index cfd070357..d74f352b9 100644 --- a/Notes/02_Working_with_data/04_Sequences.md +++ b/Notes/02_Working_with_data/04_Sequences.md @@ -98,8 +98,10 @@ There are some common functions to reduce a sequence to a single value. >>> s = [1, 2, 3, 4] >>> sum(s) 10 ->>> min(s) 1 ->>> max(s) 4 +>>> min(s) +1 +>>> max(s) +4 >>> t = ['Hello', 'World'] >>> max(t) 'World' From 22386190b62ceff2b05cd3b4242ed28c4841b20b Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 3 Jun 2020 12:21:48 +0200 Subject: [PATCH 09/89] Fix typo in Working with data/Objects --- Notes/02_Working_with_data/07_Objects.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/02_Working_with_data/07_Objects.md b/Notes/02_Working_with_data/07_Objects.md index cf20193ff..35922cd12 100644 --- a/Notes/02_Working_with_data/07_Objects.md +++ b/Notes/02_Working_with_data/07_Objects.md @@ -146,7 +146,7 @@ This is known as a shallow copy. Here is a picture. ### Deep copies -Sometimes you need to make a copy of an object and all the objects contained withn it. +Sometimes you need to make a copy of an object and all the objects contained within it. You can use the `copy` module for this: ```python From ac47b13b39fca946483ef03b32af31dd7f12f6e6 Mon Sep 17 00:00:00 2001 From: Phil D <40214783+philodavies@users.noreply.github.com> Date: Fri, 5 Jun 2020 12:48:57 -0400 Subject: [PATCH 10/89] Update 00_Overview.md Add closing parenthesis for next topic --- Notes/07_Advanced_Topics/00_Overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/07_Advanced_Topics/00_Overview.md b/Notes/07_Advanced_Topics/00_Overview.md index b0c6a12fd..74005f17e 100644 --- a/Notes/07_Advanced_Topics/00_Overview.md +++ b/Notes/07_Advanced_Topics/00_Overview.md @@ -18,4 +18,4 @@ to seek more advanced material to fill out details. * [7.4 Function decorators](04_Function_decorators.md) * [7.5 Static and class methods](05_Decorated_methods.md) -[Contents](../Contents.md) \| [Prev (6 Generators)](../06_Generators/00_Overview.md) \| [Next (8 Testing and Debugging](../08_Testing_debugging/00_Overview.md) +[Contents](../Contents.md) \| [Prev (6 Generators)](../06_Generators/00_Overview.md) \| [Next (8 Testing and Debugging)](../08_Testing_debugging/00_Overview.md) From 32b295cdde71dc41bd4bd609033a41fede88cba7 Mon Sep 17 00:00:00 2001 From: echasnovski Date: Sat, 6 Jun 2020 13:21:52 +0300 Subject: [PATCH 11/89] Make "List construction" example in '02_Containers.md' executable. --- Notes/02_Working_with_data/02_Containers.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Notes/02_Working_with_data/02_Containers.md b/Notes/02_Working_with_data/02_Containers.md index c3b53731a..40d46d933 100644 --- a/Notes/02_Working_with_data/02_Containers.md +++ b/Notes/02_Working_with_data/02_Containers.md @@ -52,9 +52,10 @@ An example when reading records from a file. records = [] # Initial empty list with open('Data/portfolio.csv', 'rt') as f: + next(f) # Skip header for line in f: row = line.split(',') - records.append((row[0], int(row[1])), float(row[2])) + records.append((row[0], int(row[1]), float(row[2]))) ``` ### Dicts as a Container From f760db409758766d879c5ac5e7d68a4b525e16f0 Mon Sep 17 00:00:00 2001 From: Ivan Seleznev Date: Sat, 6 Jun 2020 16:09:01 +0545 Subject: [PATCH 12/89] Fix grammar and typos --- Notes/01_Introduction/03_Numbers.md | 4 ++-- Notes/01_Introduction/04_Strings.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Notes/01_Introduction/03_Numbers.md b/Notes/01_Introduction/03_Numbers.md index eb6db46a8..f19634cb7 100644 --- a/Notes/01_Introduction/03_Numbers.md +++ b/Notes/01_Introduction/03_Numbers.md @@ -106,7 +106,7 @@ x ** y Power abs(x) Absolute Value ``` -Theses are the same operators as Integers, except for the bit-wise operators. +These are the same operators as Integers, except for the bit-wise operators. Additional math functions are found in the `math` module. ```python @@ -242,7 +242,7 @@ Months 309 ### Exercise 1.11: Bonus -While you’re at it, fix the program to correct the for overpayment that occurs in the last month. +While you’re at it, fix the program to correct for the overpayment that occurs in the last month. ### Exercise 1.12: A Mystery diff --git a/Notes/01_Introduction/04_Strings.md b/Notes/01_Introduction/04_Strings.md index 9e6fa49c0..2c0eed867 100644 --- a/Notes/01_Introduction/04_Strings.md +++ b/Notes/01_Introduction/04_Strings.md @@ -2,7 +2,7 @@ # 1.4 Strings -This section introduces way to work with text. +This section introduces ways to work with text. ### Representing Literal Text @@ -134,7 +134,7 @@ t = s.replace('Hello' , 'Hallo') # 'Hallo world' **More string methods:** Strings have a wide variety of other methods for testing and manipulating the text data. -This is small sample of methods: +This is a small sample of methods: ```python s.endswith(suffix) # Check if string ends with suffix From 222ed8eb2fc06667eeaa186ef29b7592691eb443 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Sat, 6 Jun 2020 09:09:38 -0500 Subject: [PATCH 13/89] Added note about blank line --- Notes/02_Working_with_data/02_Containers.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Notes/02_Working_with_data/02_Containers.md b/Notes/02_Working_with_data/02_Containers.md index c3b53731a..f67be69c1 100644 --- a/Notes/02_Working_with_data/02_Containers.md +++ b/Notes/02_Working_with_data/02_Containers.md @@ -105,6 +105,11 @@ with open('Data/prices.csv', 'rt') as f: prices[row[0]] = float(row[1]) ``` +Note: If you try this on the `Data/prices.csv` file, you'll find that +it almost works--there's a blank line at the end that causes it to +crash. You'll need to figure out some way to modify the code to +account for that (see Exercise 2.6). + ### Dictionary Lookups You can test the existence of a key. From bd6db38e74ae4fb4ae4325a1fab7e7b65a71cf63 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Sat, 6 Jun 2020 09:11:45 -0500 Subject: [PATCH 14/89] Clarified wording --- Notes/01_Introduction/02_Hello_world.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/01_Introduction/02_Hello_world.md b/Notes/01_Introduction/02_Hello_world.md index 8871198a7..0a9883dbb 100644 --- a/Notes/01_Introduction/02_Hello_world.md +++ b/Notes/01_Introduction/02_Hello_world.md @@ -58,7 +58,7 @@ interact with the interpreter. Let's take a closer look at the elements of the REPL: - `>>>` is the interpreter prompt for starting a new statement. -- `...` is the interpreter prompt for continuing a statements. Enter a blank line to finish typing and run the statements. +- `...` is the interpreter prompt for continuing a statement. Enter a blank line to finish typing and run what you've entered. The `...` prompt may or may not be shown depending on your environment. For this course, it is shown as blanks to make it easier to cut/paste code samples. From 9d82b096c68b909629b1d9948a93bedf23b17e45 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Sat, 6 Jun 2020 09:14:06 -0500 Subject: [PATCH 15/89] Fix typos --- Notes/05_Object_model/01_Dicts_revisited.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Notes/05_Object_model/01_Dicts_revisited.md b/Notes/05_Object_model/01_Dicts_revisited.md index 61cb6d505..777d2843c 100644 --- a/Notes/05_Object_model/01_Dicts_revisited.md +++ b/Notes/05_Object_model/01_Dicts_revisited.md @@ -7,7 +7,7 @@ involving dictionaries. This section discusses that. ### Dictionaries, Revisited -Remember that a dictionary is a collection of names values. +Remember that a dictionary is a collection of named values. ```python stock = { @@ -58,7 +58,7 @@ A dictionary holds the instance data, `__dict__`. ```python >>> s = Stock('GOOG', 100, 490.1) >>> s.__dict__ -{'name' : 'GOOG','shares' : 100, 'price': 490.1 } +{'name' : 'GOOG', 'shares' : 100, 'price': 490.1 } ``` You populate this dict (and instance) when assigning to `self`. @@ -271,7 +271,7 @@ e = E() e.attr ``` -A attribute search process is carried out, but what is the order? That's a problem. +An attribute search process is carried out, but what is the order? That's a problem. Python uses *cooperative multiple inheritance* which obeys some rules about class ordering. From 06c1f681050407919126f2520512fd26920f4f50 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Sat, 6 Jun 2020 09:20:24 -0500 Subject: [PATCH 16/89] Fixed gzip example --- Notes/01_Introduction/06_Files.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Notes/01_Introduction/06_Files.md b/Notes/01_Introduction/06_Files.md index fb9bb9f01..8a960f905 100644 --- a/Notes/01_Introduction/06_Files.md +++ b/Notes/01_Introduction/06_Files.md @@ -220,7 +220,7 @@ Try it: ```python >>> import gzip ->>> with gzip.open('Data/portfolio.csv.gz') as f: +>>> with gzip.open('Data/portfolio.csv.gz', 'rt') as f: for line in f: print(line, end='') @@ -228,6 +228,9 @@ Try it: >>> ``` +Note: Including the file mode of `'rt'` is critical here. If you forget that, +you'll get byte strings instead of normal text strings. + ### Commentary: Shouldn't we being using Pandas for this? Data scientists are quick to point out that libraries like From 5cf2cdee1dc834096093ed7e536e63a9e52bbe4a Mon Sep 17 00:00:00 2001 From: Ivan Seleznev Date: Sun, 7 Jun 2020 11:51:46 +0545 Subject: [PATCH 17/89] Fix grammar and typos --- Notes/01_Introduction/06_Files.md | 2 +- Notes/02_Working_with_data/01_Datatypes.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Notes/01_Introduction/06_Files.md b/Notes/01_Introduction/06_Files.md index fb9bb9f01..d39dfadc3 100644 --- a/Notes/01_Introduction/06_Files.md +++ b/Notes/01_Introduction/06_Files.md @@ -228,7 +228,7 @@ Try it: >>> ``` -### Commentary: Shouldn't we being using Pandas for this? +### Commentary: Shouldn't we be using Pandas for this? Data scientists are quick to point out that libraries like [Pandas](https://pandas.pydata.org) already have a function for diff --git a/Notes/02_Working_with_data/01_Datatypes.md b/Notes/02_Working_with_data/01_Datatypes.md index 9a038de7f..5e7cfcbdd 100644 --- a/Notes/02_Working_with_data/01_Datatypes.md +++ b/Notes/02_Working_with_data/01_Datatypes.md @@ -58,7 +58,7 @@ Sometimes the `()` are omitted in the syntax. s = 'GOOG', 100, 490.1 ``` -Special cases (0-tuple, 1-typle). +Special cases (0-tuple, 1-tuple). ```python t = () # An empty tuple From 1d2fbbbfd8a4647b1a29d37e15826fd67078f910 Mon Sep 17 00:00:00 2001 From: Ivan Seleznev <54471250+pacmansu@users.noreply.github.com> Date: Sun, 7 Jun 2020 12:37:10 +0545 Subject: [PATCH 18/89] Update 06_Files.md --- Notes/01_Introduction/06_Files.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Notes/01_Introduction/06_Files.md b/Notes/01_Introduction/06_Files.md index fb9bb9f01..8a960f905 100644 --- a/Notes/01_Introduction/06_Files.md +++ b/Notes/01_Introduction/06_Files.md @@ -220,7 +220,7 @@ Try it: ```python >>> import gzip ->>> with gzip.open('Data/portfolio.csv.gz') as f: +>>> with gzip.open('Data/portfolio.csv.gz', 'rt') as f: for line in f: print(line, end='') @@ -228,6 +228,9 @@ Try it: >>> ``` +Note: Including the file mode of `'rt'` is critical here. If you forget that, +you'll get byte strings instead of normal text strings. + ### Commentary: Shouldn't we being using Pandas for this? Data scientists are quick to point out that libraries like From d180980697da0a2d3beaeb29a2702944aac23561 Mon Sep 17 00:00:00 2001 From: Ivan Seleznev <54471250+pacmansu@users.noreply.github.com> Date: Sun, 7 Jun 2020 14:23:58 +0545 Subject: [PATCH 19/89] Fix grammar --- Notes/02_Working_with_data/02_Containers.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Notes/02_Working_with_data/02_Containers.md b/Notes/02_Working_with_data/02_Containers.md index 131fdea2d..2d403db1e 100644 --- a/Notes/02_Working_with_data/02_Containers.md +++ b/Notes/02_Working_with_data/02_Containers.md @@ -341,7 +341,7 @@ accessed by key names instead of numeric column numbers. This is often preferred because the resulting code is easier to read later. Viewing large dictionaries and lists can be messy. To clean up the -output for debugging, considering using the `pprint` function. +output for debugging, consider using the `pprint` function. ```python >>> from pprint import pprint @@ -443,9 +443,9 @@ interactively to make sure it works: ### Exercise 2.7: Finding out if you can retire Tie all of this work together by adding a few additional statements to -your `report.py` program that compute gain/loss. These statements +your `report.py` program that computes gain/loss. These statements should take the list of stocks in Exercise 2.5 and the dictionary of -prices in Exercise 2.6 and computes the current value of the portfolio +prices in Exercise 2.6 and compute the current value of the portfolio along with the gain/loss. [Contents](../Contents.md) \| [Previous (2.1 Datatypes)](01_Datatypes.md) \| [Next (2.3 Formatting)](03_Formatting.md) From c04dc3e178b138a60e842d00be4953092c9b5cce Mon Sep 17 00:00:00 2001 From: David Beazley Date: Sun, 7 Jun 2020 07:21:06 -0500 Subject: [PATCH 20/89] Fixed end condition on mortgage calculation --- Notes/01_Introduction/03_Numbers.md | 9 +++++---- Solutions/1_10/mortgage.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Notes/01_Introduction/03_Numbers.md b/Notes/01_Introduction/03_Numbers.md index eb6db46a8..1532848cd 100644 --- a/Notes/01_Introduction/03_Numbers.md +++ b/Notes/01_Introduction/03_Numbers.md @@ -234,10 +234,11 @@ The output should look something like this: 4 10736.44 497581.83 5 13420.55 496970.98 ... -308 875705.88 674.44 -309 878389.99 -2006.86 -Total paid 878389.99 -Months 309 +308 874705.88 2971.43 +309 877389.99 299.7 +310 880074.1 -2383.16 +Total paid 880074.1 +Months 310 ``` ### Exercise 1.11: Bonus diff --git a/Solutions/1_10/mortgage.py b/Solutions/1_10/mortgage.py index 23ecacaf6..9d85119ad 100644 --- a/Solutions/1_10/mortgage.py +++ b/Solutions/1_10/mortgage.py @@ -15,7 +15,7 @@ principal = principal * (1+rate/12) - payment total_paid = total_paid + payment - if month >= extra_payment_start_month and month <= extra_payment_end_month: + if month >= extra_payment_start_month and month < extra_payment_end_month: principal = principal - extra_payment total_paid = total_paid + extra_payment From 06bc3a233f00aa6ed4bbbef6e176a9740220676b Mon Sep 17 00:00:00 2001 From: David Beazley Date: Sun, 7 Jun 2020 07:24:13 -0500 Subject: [PATCH 21/89] Fix typo --- Notes/04_Classes_objects/01_Class.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/04_Classes_objects/01_Class.md b/Notes/04_Classes_objects/01_Class.md index d63d2aad6..b7d268c70 100644 --- a/Notes/04_Classes_objects/01_Class.md +++ b/Notes/04_Classes_objects/01_Class.md @@ -143,7 +143,7 @@ If you want to operate on an instance, you always refer to it explicitly (e.g., ## Exercises Starting with this set of exercises, we start to make a series of -changes to existing code from previous sctions. It is critical that +changes to existing code from previous sections. It is critical that you have a working version of Exercise 3.18 to start. If you don't have that, please work from the solution code found in the `Solutions/3_18` directory. It's fine to copy it. From de557878ad0d3262e625fe769b00adc13eb8dfd7 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Sun, 7 Jun 2020 07:26:27 -0500 Subject: [PATCH 22/89] Fixed transposed values --- Notes/03_Program_organization/06_Design_discussion.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/03_Program_organization/06_Design_discussion.md b/Notes/03_Program_organization/06_Design_discussion.md index 5b18a6afc..9379a167e 100644 --- a/Notes/03_Program_organization/06_Design_discussion.md +++ b/Notes/03_Program_organization/06_Design_discussion.md @@ -110,7 +110,7 @@ with any file-like/iterable object. For example: >>> with gzip.open('Data/portfolio.csv.gz', 'rt') as file: ... port = fileparse.parse_csv(file, types=[str,int,float]) ... ->>> lines = ['name,shares,price', 'AA,34.23,100', 'IBM,50,91.1', 'HPE,75,45.1'] +>>> lines = ['name,shares,price', 'AA,100,34.23', 'IBM,50,91.1', 'HPE,75,45.1'] >>> port = fileparse.parse_csv(lines, types=[str,int,float]) >>> ``` From a9e8de2aba8be8426cb1874f9fd2007f21603394 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Tue, 9 Jun 2020 10:01:00 -0500 Subject: [PATCH 23/89] Minor wording change --- Notes/01_Introduction/04_Strings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/01_Introduction/04_Strings.md b/Notes/01_Introduction/04_Strings.md index 2c0eed867..162f825f3 100644 --- a/Notes/01_Introduction/04_Strings.md +++ b/Notes/01_Introduction/04_Strings.md @@ -144,7 +144,7 @@ s.isalpha() # Check if characters are alphabetic s.isdigit() # Check if characters are numeric s.islower() # Check if characters are lower-case s.isupper() # Check if characters are upper-case -s.join(slist) # Joins lists using s as delimiter +s.join(slist) # Join a list of strings using s as delimiter s.lower() # Convert to lower case s.replace(old,new) # Replace text s.rfind(t) # Search for t from end of string From 7dcc56b4086802b52fde119e2e3399e6fac4ac64 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Tue, 9 Jun 2020 15:07:05 -0500 Subject: [PATCH 24/89] Fix typo --- Notes/02_Working_with_data/02_Containers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/02_Working_with_data/02_Containers.md b/Notes/02_Working_with_data/02_Containers.md index 2d403db1e..20ac55208 100644 --- a/Notes/02_Working_with_data/02_Containers.md +++ b/Notes/02_Working_with_data/02_Containers.md @@ -315,7 +315,7 @@ Experiment with this new function in the same manner as you did in Exercise 2.4. ```python ->>> portfolio = read_portfolio('portfolio.csv') +>>> portfolio = read_portfolio('Data/portfolio.csv') >>> portfolio [{'name': 'AA', 'shares': 100, 'price': 32.2}, {'name': 'IBM', 'shares': 50, 'price': 91.1}, {'name': 'CAT', 'shares': 150, 'price': 83.44}, {'name': 'MSFT', 'shares': 200, 'price': 51.23}, From e28e72642ad2163e9b56041706c3d19495bd1156 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Wed, 10 Jun 2020 08:41:51 -0500 Subject: [PATCH 25/89] Fixed line spacing issue --- Notes/05_Object_model/02_Classes_encapsulation.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Notes/05_Object_model/02_Classes_encapsulation.md b/Notes/05_Object_model/02_Classes_encapsulation.md index 07ea94757..2471df944 100644 --- a/Notes/05_Object_model/02_Classes_encapsulation.md +++ b/Notes/05_Object_model/02_Classes_encapsulation.md @@ -94,7 +94,9 @@ One approach: introduce accessor methods. ```python class Stock: def __init__(self, name, shares, price): - self.name = name self.set_shares(shares) self.price = price + self.name = name + self.set_shares(shares) + self.price = price # Function that layers the "get" operation def get_shares(self): From 611428ec1e33c34908467693ee218d762ffe685e Mon Sep 17 00:00:00 2001 From: David Beazley Date: Wed, 10 Jun 2020 08:42:34 -0500 Subject: [PATCH 26/89] Fix typo --- Notes/05_Object_model/02_Classes_encapsulation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/05_Object_model/02_Classes_encapsulation.md b/Notes/05_Object_model/02_Classes_encapsulation.md index 2471df944..49feb3c81 100644 --- a/Notes/05_Object_model/02_Classes_encapsulation.md +++ b/Notes/05_Object_model/02_Classes_encapsulation.md @@ -214,7 +214,7 @@ can fix this. ### Decorator Syntax -The `@` syntax is known as *decoration". It specifies a modifier +The `@` syntax is known as "decoration". It specifies a modifier that's applied to the function definition that immediately follows. ```python From cdf6d4b9000c38fc9cd7e636b41af5b1cd19e554 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Wed, 10 Jun 2020 08:43:15 -0500 Subject: [PATCH 27/89] Fix typo --- Notes/02_Working_with_data/07_Objects.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/02_Working_with_data/07_Objects.md b/Notes/02_Working_with_data/07_Objects.md index 35922cd12..025ecf48f 100644 --- a/Notes/02_Working_with_data/07_Objects.md +++ b/Notes/02_Working_with_data/07_Objects.md @@ -238,7 +238,7 @@ items[1].sqrt(2) # math except items[2]: # ValueError ``` -With great power come responsibility. Just because you can do that doesn't mean you should. +With great power comes responsibility. Just because you can do that doesn't mean you should. ## Exercises From 79d47df60074bb680c527abb1a7862afbe941b5a Mon Sep 17 00:00:00 2001 From: David Beazley Date: Tue, 16 Jun 2020 14:03:54 -0500 Subject: [PATCH 28/89] Fixed link --- Notes/InstructorNotes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/InstructorNotes.md b/Notes/InstructorNotes.md index 07568f317..69808d7ea 100644 --- a/Notes/InstructorNotes.md +++ b/Notes/InstructorNotes.md @@ -334,6 +334,6 @@ Second goal, write a simple setup.py file that they can use to package up the code and give it away to someone. That's it. End of the course. -[Contents](Contents.html) +[Contents](Contents.md) From 11b0a832a8da9970e92693588fc6933f457f48fd Mon Sep 17 00:00:00 2001 From: David Beazley Date: Thu, 18 Jun 2020 19:34:13 -0500 Subject: [PATCH 29/89] Fix typo --- Notes/03_Program_organization/01_Script.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/03_Program_organization/01_Script.md b/Notes/03_Program_organization/01_Script.md index 07bc91dd9..11fdb1809 100644 --- a/Notes/03_Program_organization/01_Script.md +++ b/Notes/03_Program_organization/01_Script.md @@ -102,7 +102,7 @@ def bar(x): statements # OR -def bar(x) +def bar(x): statements def foo(x): From e030d694963438a0c828019d7973bb56d85f6ea7 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Thu, 18 Jun 2020 19:42:47 -0500 Subject: [PATCH 30/89] Minor refinement on range --- Solutions/1_10/mortgage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Solutions/1_10/mortgage.py b/Solutions/1_10/mortgage.py index 9d85119ad..dabd94fc3 100644 --- a/Solutions/1_10/mortgage.py +++ b/Solutions/1_10/mortgage.py @@ -15,7 +15,7 @@ principal = principal * (1+rate/12) - payment total_paid = total_paid + payment - if month >= extra_payment_start_month and month < extra_payment_end_month: + if month > extra_payment_start_month and month <= extra_payment_end_month: principal = principal - extra_payment total_paid = total_paid + extra_payment From 87994d0bdd2019347f02bc20b202ecd7b93c4f42 Mon Sep 17 00:00:00 2001 From: Alex DeLorenzo <3579286+alexdelorenzo@users.noreply.github.com> Date: Thu, 18 Jun 2020 21:02:41 -0400 Subject: [PATCH 31/89] Fix grammar "The find" -> "To find" --- Notes/05_Object_model/01_Dicts_revisited.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/05_Object_model/01_Dicts_revisited.md b/Notes/05_Object_model/01_Dicts_revisited.md index 777d2843c..52760303c 100644 --- a/Notes/05_Object_model/01_Dicts_revisited.md +++ b/Notes/05_Object_model/01_Dicts_revisited.md @@ -248,7 +248,7 @@ You can view it. >>> ``` -This chain is called the **Method Resolution Order**. The find an +This chain is called the **Method Resolution Order**. To find an attribute, Python walks the MRO in order. The first match wins. ### MRO in Multiple Inheritance From c2570c572f4052e8e44c157e81258715649db20b Mon Sep 17 00:00:00 2001 From: David Litvak Bruno Date: Fri, 19 Jun 2020 09:51:49 +0200 Subject: [PATCH 32/89] Adding missing parenthesis on link --- Notes/07_Advanced_Topics/00_Overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/07_Advanced_Topics/00_Overview.md b/Notes/07_Advanced_Topics/00_Overview.md index 74005f17e..dacbcfa2a 100644 --- a/Notes/07_Advanced_Topics/00_Overview.md +++ b/Notes/07_Advanced_Topics/00_Overview.md @@ -1,4 +1,4 @@ -[Contents](../Contents.md) \| [Prev (6 Generators)](../06_Generators/00_Overview.md) \| [Next (8 Testing and Debugging](../08_Testing_debugging/00_Overview.md) +[Contents](../Contents.md) \| [Prev (6 Generators)](../06_Generators/00_Overview.md) \| [Next (8 Testing and Debugging)](../08_Testing_debugging/00_Overview.md) # 7. Advanced Topics From 17547d2d7e2bd826661aa271cab4ca44d5473bbc Mon Sep 17 00:00:00 2001 From: David Litvak Bruno Date: Fri, 19 Jun 2020 09:53:24 +0200 Subject: [PATCH 33/89] Change title to match the section convention --- Notes/08_Testing_debugging/00_Overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/08_Testing_debugging/00_Overview.md b/Notes/08_Testing_debugging/00_Overview.md index 37841d93c..d1c1bbc6a 100644 --- a/Notes/08_Testing_debugging/00_Overview.md +++ b/Notes/08_Testing_debugging/00_Overview.md @@ -1,6 +1,6 @@ [Contents](../Contents.md) \| [Prev (7 Advanced Topics)](../07_Advanced_Topics/00_Overview.md) \| [Next (9 Packages)](../09_Packages/00_Overview.md) -# 8. Overview +# 8. Testing and debugging This section introduces a few basic topics related to testing, logging, and debugging. From 9e86603ccf1d3abcdf2404b429af2d757ab7e12d Mon Sep 17 00:00:00 2001 From: David Beazley Date: Fri, 19 Jun 2020 06:45:21 -0500 Subject: [PATCH 34/89] Fix typo --- Notes/07_Advanced_Topics/01_Variable_arguments.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/07_Advanced_Topics/01_Variable_arguments.md b/Notes/07_Advanced_Topics/01_Variable_arguments.md index cc1f9efb0..6fe66ba0a 100644 --- a/Notes/07_Advanced_Topics/01_Variable_arguments.md +++ b/Notes/07_Advanced_Topics/01_Variable_arguments.md @@ -92,7 +92,7 @@ numbers = (2,3,4) f(1, *numbers) # Same as f(1,2,3,4) ``` -Dictionaries can also be expaded into keyword arguments. +Dictionaries can also be expanded into keyword arguments. ```python options = { From 12ff9195c1cb843167b6a470e958d3670939532c Mon Sep 17 00:00:00 2001 From: Tom Burrows Date: Fri, 19 Jun 2020 15:23:36 +0100 Subject: [PATCH 35/89] Fix typo (porty-add -> porty-app) --- Notes/09_Packages/01_Packages.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/09_Packages/01_Packages.md b/Notes/09_Packages/01_Packages.md index 24fcb35fe..96133bed8 100644 --- a/Notes/09_Packages/01_Packages.md +++ b/Notes/09_Packages/01_Packages.md @@ -243,7 +243,7 @@ package. One level up. ```python #!/usr/bin/env python3 -# porty-add/script.py +# porty-app/script.py import sys import porty From 3f0b9b0975cf80988e952684f728984259775bf0 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Fri, 19 Jun 2020 20:50:49 -0500 Subject: [PATCH 36/89] Fixed link --- Notes/Contents.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/Contents.md b/Notes/Contents.md index ef7299266..57199d7c0 100644 --- a/Notes/Contents.md +++ b/Notes/Contents.md @@ -16,7 +16,7 @@ Please see the [Instructor Notes](InstructorNotes.md) if you plan on teaching the course. -[Home](..) +[Home](../README.md) From b5765a22aba161aec25248785cef171aaa48771e Mon Sep 17 00:00:00 2001 From: David Beazley Date: Fri, 19 Jun 2020 21:00:59 -0500 Subject: [PATCH 37/89] Added Github pages link --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e9538de6e..21efa4540 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ in-person groups since 2007. Traders, systems admins, astronomers, tinkerers, and even a few hundred rocket scientists who used Python to help land a rover on Mars--they've all taken this course. Now, I'm pleased to make it available under a Creative Commons license. Enjoy! -[GitHub Repo](https://github.com/dabeaz-course/practical-python). + +[GitHub Pages](https://dabeaz-course.github.io/practical-python) | [GitHub Repo](https://github.com/dabeaz-course/practical-python). --David Beazley ([https://dabeaz.com](https://dabeaz.com)), [@dabeaz](https://twitter.com/dabeaz) From a12eac956d434ac42761c8e7ec3229ca6041f0b3 Mon Sep 17 00:00:00 2001 From: Paul Deng Date: Sat, 20 Jun 2020 15:12:17 -0400 Subject: [PATCH 38/89] Update 04_Strings.md Personally, I think this statement should have an emphasize to mark its relative importance. --- Notes/01_Introduction/04_Strings.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Notes/01_Introduction/04_Strings.md b/Notes/01_Introduction/04_Strings.md index 162f825f3..804f52514 100644 --- a/Notes/01_Introduction/04_Strings.md +++ b/Notes/01_Introduction/04_Strings.md @@ -28,8 +28,8 @@ Normally strings may only span a single line. Triple quotes capture all text enc including all formatting. There is no difference between using single (') versus double (") -quotes. The same type of quote used to start a string must be used to -terminate it. +quotes. *However, the same type of quote used to start a string must be used to +terminate it*. ### String escape codes From 2f2f5eaeb567242a12d9ca0c4f6b38a799a181f8 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Sun, 21 Jun 2020 06:36:55 -0500 Subject: [PATCH 39/89] Fix typo --- Notes/01_Introduction/02_Hello_world.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Notes/01_Introduction/02_Hello_world.md b/Notes/01_Introduction/02_Hello_world.md index 0a9883dbb..1cc1bcbe5 100644 --- a/Notes/01_Introduction/02_Hello_world.md +++ b/Notes/01_Introduction/02_Hello_world.md @@ -241,7 +241,7 @@ while num_bills * bill_thickness < sears_height: day = day + 1 num_bills = num_bills * 2 -print('Number of days', days) +print('Number of days', day) ``` The statements indented below the `while` will execute as long as the expression after the `while` is `true`. @@ -257,7 +257,7 @@ while num_bills * bill_thickness < sears_height: day = day + 1 num_bills = num_bills * 2 -print('Number of days', days) +print('Number of days', day) ``` Indentation groups the following statements together as the operations that repeat: From 24cd6df9cfb243bde7e90f01f4d64c385c899b6c Mon Sep 17 00:00:00 2001 From: David Beazley Date: Sun, 21 Jun 2020 06:42:00 -0500 Subject: [PATCH 40/89] Minor tweak to exercise 1.9 --- Notes/01_Introduction/03_Numbers.md | 4 ++-- Solutions/1_10/mortgage.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Notes/01_Introduction/03_Numbers.md b/Notes/01_Introduction/03_Numbers.md index 1627bd4e4..202f07142 100644 --- a/Notes/01_Introduction/03_Numbers.md +++ b/Notes/01_Introduction/03_Numbers.md @@ -213,14 +213,14 @@ Modify the program so that extra payment information can be more generally handl Make it so that the user can set these variables: ```python -extra_payment_start_month = 60 +extra_payment_start_month = 61 extra_payment_end_month = 108 extra_payment = 1000 ``` Make the program look at these variables and calculate the total paid appropriately. -How much will Dave pay if he pays an extra $1000/month for 4 years starting in year 5 of the mortgage? +How much will Dave pay if he pays an extra $1000/month for 4 years starting in year 5 of the mortgage? ### Exercise 1.10: Making a table diff --git a/Solutions/1_10/mortgage.py b/Solutions/1_10/mortgage.py index dabd94fc3..51e477519 100644 --- a/Solutions/1_10/mortgage.py +++ b/Solutions/1_10/mortgage.py @@ -7,7 +7,7 @@ month = 0 extra_payment = 1000.0 -extra_payment_start_month = 60 +extra_payment_start_month = 61 extra_payment_end_month = 108 while principal > 0: @@ -15,7 +15,7 @@ principal = principal * (1+rate/12) - payment total_paid = total_paid + payment - if month > extra_payment_start_month and month <= extra_payment_end_month: + if month >= extra_payment_start_month and month <= extra_payment_end_month: principal = principal - extra_payment total_paid = total_paid + extra_payment From 5ea03f60f99f832c0291f2f936c1e30ae2afe456 Mon Sep 17 00:00:00 2001 From: Gabriel Sroka Date: Mon, 22 Jun 2020 13:49:21 -0700 Subject: [PATCH 41/89] Update 03_Debugging.md fix minor typo --- Notes/08_Testing_debugging/03_Debugging.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/08_Testing_debugging/03_Debugging.md b/Notes/08_Testing_debugging/03_Debugging.md index 378a6a36f..f8f7de0a6 100644 --- a/Notes/08_Testing_debugging/03_Debugging.md +++ b/Notes/08_Testing_debugging/03_Debugging.md @@ -4,7 +4,7 @@ ### Debugging Tips -So, you're program has crashed... +So, your program has crashed... ```bash bash % python3 blah.py From 41a4a1e3c16f993007971df44f57e74d8fc7badc Mon Sep 17 00:00:00 2001 From: David Beazley Date: Tue, 30 Jun 2020 07:09:04 -0500 Subject: [PATCH 42/89] Minor fix to filename --- Notes/03_Program_organization/01_Script.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/03_Program_organization/01_Script.md b/Notes/03_Program_organization/01_Script.md index 11fdb1809..cd5626c5c 100644 --- a/Notes/03_Program_organization/01_Script.md +++ b/Notes/03_Program_organization/01_Script.md @@ -283,7 +283,7 @@ interactively after running your program: >>> files = ['Data/portfolio.csv', 'Data/portfolio2.csv'] >>> for name in files: print(f'{name:-^43s}') - portfolio_report(name, 'prices.csv') + portfolio_report(name, 'Data/prices.csv') print() ... look at the output ... From be34a7bc2f314919fd04c0463d68c2bbb32f060a Mon Sep 17 00:00:00 2001 From: David Beazley Date: Tue, 30 Jun 2020 09:32:22 -0500 Subject: [PATCH 43/89] Fix typo --- Notes/02_Working_with_data/01_Datatypes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/02_Working_with_data/01_Datatypes.md b/Notes/02_Working_with_data/01_Datatypes.md index 5e7cfcbdd..cf79fd872 100644 --- a/Notes/02_Working_with_data/01_Datatypes.md +++ b/Notes/02_Working_with_data/01_Datatypes.md @@ -338,7 +338,7 @@ above. Change the number of shares to 75. ```python >>> d['shares'] = 75 >>> d -{'name': 'AA', 'shares': 75, 'price': 75} +{'name': 'AA', 'shares': 75, 'price': 32.2 } >>> ``` From ced01f5373ec711c9ebf47d2ea556755c746aa0c Mon Sep 17 00:00:00 2001 From: Chad Bean Date: Wed, 1 Jul 2020 08:35:53 -0400 Subject: [PATCH 44/89] Fix syntax for inspecting imported numpy package --- Notes/09_Packages/02_Third_party.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Notes/09_Packages/02_Third_party.md b/Notes/09_Packages/02_Third_party.md index 2fa5e5508..94f236a45 100644 --- a/Notes/09_Packages/02_Third_party.md +++ b/Notes/09_Packages/02_Third_party.md @@ -50,6 +50,7 @@ the same steps as above: ```python >>> import numpy +>>> numpy >>> ``` From b8c570a6b7de0c070c397609f77b0433293107a5 Mon Sep 17 00:00:00 2001 From: caticoa3 Date: Wed, 1 Jul 2020 16:49:07 -0700 Subject: [PATCH 45/89] Update 03_Numbers.md The expected output does not match that of the correct solution, provided in morgage.py --- Notes/01_Introduction/03_Numbers.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Notes/01_Introduction/03_Numbers.md b/Notes/01_Introduction/03_Numbers.md index 202f07142..3f6013398 100644 --- a/Notes/01_Introduction/03_Numbers.md +++ b/Notes/01_Introduction/03_Numbers.md @@ -234,9 +234,9 @@ The output should look something like this: 4 10736.44 497581.83 5 13420.55 496970.98 ... -308 874705.88 2971.43 -309 877389.99 299.7 -310 880074.1 -2383.16 +308 874705.88 3478.83 +309 877389.99 809.21 +310 880074.1 -1871.53 Total paid 880074.1 Months 310 ``` From 979a2e93281791bb168eb85394bd0f093b249d09 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Wed, 1 Jul 2020 19:33:03 -0500 Subject: [PATCH 46/89] Fixed output problem --- Notes/01_Introduction/03_Numbers.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Notes/01_Introduction/03_Numbers.md b/Notes/01_Introduction/03_Numbers.md index 202f07142..3f6013398 100644 --- a/Notes/01_Introduction/03_Numbers.md +++ b/Notes/01_Introduction/03_Numbers.md @@ -234,9 +234,9 @@ The output should look something like this: 4 10736.44 497581.83 5 13420.55 496970.98 ... -308 874705.88 2971.43 -309 877389.99 299.7 -310 880074.1 -2383.16 +308 874705.88 3478.83 +309 877389.99 809.21 +310 880074.1 -1871.53 Total paid 880074.1 Months 310 ``` From 99aa5ae131103d41e349c33963ab25a56676071c Mon Sep 17 00:00:00 2001 From: bid0uille <48789037+bid0uille@users.noreply.github.com> Date: Thu, 2 Jul 2020 15:22:24 +0200 Subject: [PATCH 47/89] Fix missing new line Insert a newline at line 52 of 02.03 part. --- Notes/02_Working_with_data/03_Formatting.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Notes/02_Working_with_data/03_Formatting.md b/Notes/02_Working_with_data/03_Formatting.md index ae88c83b3..a3ec1e5f7 100644 --- a/Notes/02_Working_with_data/03_Formatting.md +++ b/Notes/02_Working_with_data/03_Formatting.md @@ -49,7 +49,8 @@ b Binary integer x Hexadecimal integer f Float as [-]m.dddddd e Float as [-]m.dddddde+-xx -g Float, but selective use of E notation s String +g Float, but selective use of E notation +s String c Character (from integer) ``` From ee21b33e3fe80ee77db49e47f4baffa4502eeec4 Mon Sep 17 00:00:00 2001 From: bid0uille <48789037+bid0uille@users.noreply.github.com> Date: Thu, 2 Jul 2020 16:21:19 +0200 Subject: [PATCH 48/89] Fix missing word Word 'number' missing in 02.04 part. --- Notes/02_Working_with_data/04_Sequences.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/02_Working_with_data/04_Sequences.md b/Notes/02_Working_with_data/04_Sequences.md index d74f352b9..51e2df4bf 100644 --- a/Notes/02_Working_with_data/04_Sequences.md +++ b/Notes/02_Working_with_data/04_Sequences.md @@ -242,7 +242,7 @@ for x, y in points: ``` When using multiple variables, each tuple is *unpacked* into a set of iteration variables. -The number of variables must match the of items in each tuple. +The number of variables must match the number of items in each tuple. ### zip() function From b6a9aeae46f7450ca3756106e9a2a389bf75122b Mon Sep 17 00:00:00 2001 From: altvec Date: Thu, 2 Jul 2020 23:32:40 +0500 Subject: [PATCH 49/89] Fix missing new line --- Notes/04_Classes_objects/03_Special_methods.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Notes/04_Classes_objects/03_Special_methods.md b/Notes/04_Classes_objects/03_Special_methods.md index 460009ef2..72a8ef936 100644 --- a/Notes/04_Classes_objects/03_Special_methods.md +++ b/Notes/04_Classes_objects/03_Special_methods.md @@ -147,7 +147,8 @@ A method that has not yet been invoked by the function call operator `()` is kno It operates on the instance where it originated. ```python ->>> s = Stock('GOOG', 100, 490.10) >>> s +>>> s = Stock('GOOG', 100, 490.10) +>>> s >>> c = s.cost >>> c From 58c9c3b5039a5c672b1e333df592cc557120b61c Mon Sep 17 00:00:00 2001 From: arf Date: Fri, 3 Jul 2020 23:04:35 +0200 Subject: [PATCH 50/89] fix typo in 02/07 line 14 'a~n~ list' --- Notes/02_Working_with_data/07_Objects.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/02_Working_with_data/07_Objects.md b/Notes/02_Working_with_data/07_Objects.md index 025ecf48f..8710e3038 100644 --- a/Notes/02_Working_with_data/07_Objects.md +++ b/Notes/02_Working_with_data/07_Objects.md @@ -11,7 +11,7 @@ Many operations in Python are related to *assigning* or *storing* values. ```python a = value # Assignment to a variable -s[n] = value # Assignment to an list +s[n] = value # Assignment to a list s.append(value) # Appending to a list d['key'] = value # Adding to a dictionary ``` From 9eb78ddd9b1bc0a99af1c0bb3f4f3d55997af0d5 Mon Sep 17 00:00:00 2001 From: arf Date: Fri, 3 Jul 2020 23:15:09 +0200 Subject: [PATCH 51/89] fix missing word in 03/02 line 333 'Data/' --- Notes/03_Program_organization/02_More_functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/03_Program_organization/02_More_functions.md b/Notes/03_Program_organization/02_More_functions.md index 318ddc802..e7556aa72 100644 --- a/Notes/03_Program_organization/02_More_functions.md +++ b/Notes/03_Program_organization/02_More_functions.md @@ -332,7 +332,7 @@ follows: [{'price': '32.20', 'name': 'AA', 'shares': '100'}, {'price': '91.10', 'name': 'IBM', 'shares': '50'}, {'price': '83.44', 'name': 'CAT', 'shares': '150'}, {'price': '51.23', 'name': 'MSFT', 'shares': '200'}, {'price': '40.37', 'name': 'GE', 'shares': '95'}, {'price': '65.10', 'name': 'MSFT', 'shares': '50'}, {'price': '70.44', 'name': 'IBM', 'shares': '100'}] >>> # Read only some of the data ->>> shares_held = parse_csv('portfolio.csv', select=['name','shares']) +>>> shares_held = parse_csv('Data/portfolio.csv', select=['name','shares']) >>> shares_held [{'name': 'AA', 'shares': '100'}, {'name': 'IBM', 'shares': '50'}, {'name': 'CAT', 'shares': '150'}, {'name': 'MSFT', 'shares': '200'}, {'name': 'GE', 'shares': '95'}, {'name': 'MSFT', 'shares': '50'}, {'name': 'IBM', 'shares': '100'}] >>> From c114f9e17bca467774e9019ef4479e6d12490cac Mon Sep 17 00:00:00 2001 From: bid0uille Date: Fri, 3 Jul 2020 23:38:23 +0200 Subject: [PATCH 52/89] fix missing word in 03/03 line 344 'is' --- Notes/03_Program_organization/03_Error_checking.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/03_Program_organization/03_Error_checking.md b/Notes/03_Program_organization/03_Error_checking.md index f403507c0..d4e4779d4 100644 --- a/Notes/03_Program_organization/03_Error_checking.md +++ b/Notes/03_Program_organization/03_Error_checking.md @@ -341,7 +341,7 @@ As a general rule, it’s usually best to skip such tests and to just let the program fail on bad inputs. The traceback message will point at the source of the problem and can assist in debugging. -The main reason for adding the above check to avoid running the code +The main reason for adding the above check is to avoid running the code in a non-sensical mode (e.g., using a feature that requires column headers, but simultaneously specifying that there are no headers). From dc1f3b3aa11a3ff8d8b205ddcbdfdd0d34883337 Mon Sep 17 00:00:00 2001 From: bid0uille Date: Sat, 4 Jul 2020 00:04:28 +0200 Subject: [PATCH 53/89] fix sample output in 03/04 exercise 3.12 --- Notes/03_Program_organization/04_Modules.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Notes/03_Program_organization/04_Modules.md b/Notes/03_Program_organization/04_Modules.md index 260f715ca..22e7cf502 100644 --- a/Notes/03_Program_organization/04_Modules.md +++ b/Notes/03_Program_organization/04_Modules.md @@ -299,13 +299,13 @@ In section 2, you wrote a program `report.py` that produced a stock report like ``` Name Shares Price Change ---------- ---------- ---------- ---------- - AA 100 39.91 7.71 - IBM 50 106.11 15.01 - CAT 150 78.58 -4.86 - MSFT 200 30.47 -20.76 - GE 95 37.38 -2.99 - MSFT 50 30.47 -34.63 - IBM 100 106.11 35.67 + AA 100 9.22 -22.98 + IBM 50 106.28 15.18 + CAT 150 35.46 -47.98 + MSFT 200 20.89 -30.34 + GE 95 13.48 -26.89 + MSFT 50 20.89 -44.21 + IBM 100 106.28 35.84 ``` Take that program and modify it so that all of the input file From 79ff2b3d579dd8dfd5a453d69d9f6c7cbcfb2e90 Mon Sep 17 00:00:00 2001 From: bid0uille Date: Sat, 4 Jul 2020 00:27:04 +0200 Subject: [PATCH 54/89] fix sample output in 03/05 exercises 3.15+16 --- .../03_Program_organization/05_Main_module.md | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Notes/03_Program_organization/05_Main_module.md b/Notes/03_Program_organization/05_Main_module.md index 93df5e747..0bcce5dae 100644 --- a/Notes/03_Program_organization/05_Main_module.md +++ b/Notes/03_Program_organization/05_Main_module.md @@ -263,13 +263,13 @@ should be able to run it interatively like this: >>> report.main(['report.py', 'Data/portfolio.csv', 'Data/prices.csv']) Name Shares Price Change ---------- ---------- ---------- ---------- - AA 100 39.91 7.71 - IBM 50 106.11 15.01 - CAT 150 78.58 -4.86 - MSFT 200 30.47 -20.76 - GE 95 37.38 -2.99 - MSFT 50 30.47 -34.63 - IBM 100 106.11 35.67 + AA 100 9.22 -22.98 + IBM 50 106.28 15.18 + CAT 150 35.46 -47.98 + MSFT 200 20.89 -30.34 + GE 95 13.48 -26.89 + MSFT 50 20.89 -44.21 + IBM 100 106.28 35.84 >>> ``` @@ -291,16 +291,16 @@ execute as a script on the command line: bash $ python3 report.py Data/portfolio.csv Data/prices.csv Name Shares Price Change ---------- ---------- ---------- ---------- - AA 100 39.91 7.71 - IBM 50 106.11 15.01 - CAT 150 78.58 -4.86 - MSFT 200 30.47 -20.76 - GE 95 37.38 -2.99 - MSFT 50 30.47 -34.63 - IBM 100 106.11 35.67 + AA 100 9.22 -22.98 + IBM 50 106.28 15.18 + CAT 150 35.46 -47.98 + MSFT 200 20.89 -30.34 + GE 95 13.48 -26.89 + MSFT 50 20.89 -44.21 + IBM 100 106.28 35.84 bash $ python3 pcost.py Data/portfolio.csv Total cost: 44671.15 ``` -[Contents](../Contents.md) \| [Previous (3.4 Modules)](04_Modules.md) \| [Next (3.6 Design Discussion)](06_Design_discussion.md) \ No newline at end of file +[Contents](../Contents.md) \| [Previous (3.4 Modules)](04_Modules.md) \| [Next (3.6 Design Discussion)](06_Design_discussion.md) From d6d00e527a24f797143cf3b85cfc183bac773d79 Mon Sep 17 00:00:00 2001 From: Gunnar Hermansson Date: Tue, 7 Jul 2020 09:30:09 +0200 Subject: [PATCH 55/89] Fixed typo and added a double space to line break rendered MarkDown. --- Notes/01_Introduction/03_Numbers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/01_Introduction/03_Numbers.md b/Notes/01_Introduction/03_Numbers.md index 3f6013398..80f4e0a10 100644 --- a/Notes/01_Introduction/03_Numbers.md +++ b/Notes/01_Introduction/03_Numbers.md @@ -77,7 +77,7 @@ c = -1.345e-10 Floats are represented as double precision using the native CPU representation [IEEE 754](https://en.wikipedia.org/wiki/IEEE_754). This is the same as the `double` type in the programming language C. -> 17 digits or precision +> 17 digits of precision > Exponent from -308 to 308 Be aware that floating point numbers are inexact when representing decimals. From 9e054a0ec2ec390fc71b090fffb90f729503cdbd Mon Sep 17 00:00:00 2001 From: bid0uille <48789037+bid0uille@users.noreply.github.com> Date: Tue, 7 Jul 2020 22:44:14 +0200 Subject: [PATCH 56/89] fix typo in 09/02 line 124 was challange instead of challenge --- Notes/09_Packages/02_Third_party.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/09_Packages/02_Third_party.md b/Notes/09_Packages/02_Third_party.md index 94f236a45..2f1086cdd 100644 --- a/Notes/09_Packages/02_Third_party.md +++ b/Notes/09_Packages/02_Third_party.md @@ -121,7 +121,7 @@ different problem. ### Handling Third-Party Dependencies in Your Application If you have written an application and it has specific third-party -dependencies, one challange concerns the creation and preservation of +dependencies, one challenge concerns the creation and preservation of the environment that includes your code and the dependencies. Sadly, this has been an area of great confusion and frequent change over Python's lifetime. It continues to evolve even now. From fc7f2a30c29fa611c5ff95a7f7122f701cc5e527 Mon Sep 17 00:00:00 2001 From: sina hosseinizad Date: Wed, 29 Jul 2020 13:10:32 +0200 Subject: [PATCH 57/89] change wording in 03/02 since the file already exists --- Notes/03_Program_organization/02_More_functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/03_Program_organization/02_More_functions.md b/Notes/03_Program_organization/02_More_functions.md index e7556aa72..e169c1f98 100644 --- a/Notes/03_Program_organization/02_More_functions.md +++ b/Notes/03_Program_organization/02_More_functions.md @@ -267,7 +267,7 @@ If you were doing a lot of file parsing for real, you’d probably want to clean some of this up and make it more general purpose. That's our goal. -Start this exercise by creating a new file called +Start this exercise by opening the file called `Work/fileparse.py`. This is where we will be doing our work. ### Exercise 3.3: Reading CSV Files From f93493b28cb0fab06e7e3ddd4fc95cf54f5ac611 Mon Sep 17 00:00:00 2001 From: sina hosseinizad Date: Mon, 3 Aug 2020 12:00:42 +0200 Subject: [PATCH 58/89] Typo --- Notes/04_Classes_objects/02_Inheritance.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/04_Classes_objects/02_Inheritance.md b/Notes/04_Classes_objects/02_Inheritance.md index 360635cca..5f2db7a9f 100644 --- a/Notes/04_Classes_objects/02_Inheritance.md +++ b/Notes/04_Classes_objects/02_Inheritance.md @@ -277,7 +277,7 @@ inheritance instead. To start, focus on the steps that are involved in a creating a table. At the top of the table is a set of table headers. After that, rows -of table data appear. Let's take those steps and and put them into +of table data appear. Let's take those steps and put them into their own class. Create a file called `tableformat.py` and define the following class: From 596d360f7b4b323c233a441f287db10e23eac8b9 Mon Sep 17 00:00:00 2001 From: sina hosseinizad Date: Mon, 3 Aug 2020 16:40:38 +0200 Subject: [PATCH 59/89] fix indentation error --- Notes/05_Object_model/02_Classes_encapsulation.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Notes/05_Object_model/02_Classes_encapsulation.md b/Notes/05_Object_model/02_Classes_encapsulation.md index 49feb3c81..f3147fc74 100644 --- a/Notes/05_Object_model/02_Classes_encapsulation.md +++ b/Notes/05_Object_model/02_Classes_encapsulation.md @@ -95,8 +95,8 @@ One approach: introduce accessor methods. class Stock: def __init__(self, name, shares, price): self.name = name - self.set_shares(shares) - self.price = price + self.set_shares(shares) + self.price = price # Function that layers the "get" operation def get_shares(self): From 9e55e151e6d6ab50188919f4286e02e6d8b168b5 Mon Sep 17 00:00:00 2001 From: sina hosseinizad Date: Tue, 4 Aug 2020 09:34:30 +0200 Subject: [PATCH 60/89] misplaced #statements in expanded for loop --- Notes/06_Generators/01_Iteration_protocol.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/06_Generators/01_Iteration_protocol.md b/Notes/06_Generators/01_Iteration_protocol.md index c22fab6a2..787b02143 100644 --- a/Notes/06_Generators/01_Iteration_protocol.md +++ b/Notes/06_Generators/01_Iteration_protocol.md @@ -42,9 +42,9 @@ _iter = obj.__iter__() # Get iterator object while True: try: x = _iter.__next__() # Get next item + # statements ... except StopIteration: # No more items break - # statements ... ``` All the objects that work with the `for-loop` implement this low-level From 9245991ffcd38476f8b4cf7e1754c2972075a4ad Mon Sep 17 00:00:00 2001 From: sina hosseinizad Date: Wed, 5 Aug 2020 09:43:35 +0200 Subject: [PATCH 61/89] Add missing import to Ex6.8 --- Notes/06_Generators/03_Producers_consumers.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Notes/06_Generators/03_Producers_consumers.md b/Notes/06_Generators/03_Producers_consumers.md index ffd7845b5..eab64592b 100644 --- a/Notes/06_Generators/03_Producers_consumers.md +++ b/Notes/06_Generators/03_Producers_consumers.md @@ -124,6 +124,7 @@ opening a file--it merely operates on a sequence of lines given to it as an argument. Now, try this: ``` +>>> from follow import follow >>> lines = follow('Data/stocklog.csv') >>> ibm = filematch(lines, 'IBM') >>> for line in ibm: From ff5368975ada41823c262b0229fc13fc74059c94 Mon Sep 17 00:00:00 2001 From: sina hosseinizad Date: Thu, 6 Aug 2020 12:18:14 +0200 Subject: [PATCH 62/89] typo --- Notes/07_Advanced_Topics/03_Returning_functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/07_Advanced_Topics/03_Returning_functions.md b/Notes/07_Advanced_Topics/03_Returning_functions.md index 30e6f0772..896f8d593 100644 --- a/Notes/07_Advanced_Topics/03_Returning_functions.md +++ b/Notes/07_Advanced_Topics/03_Returning_functions.md @@ -29,7 +29,7 @@ Adding 3 4 ### Local Variables -Observe how to inner function refers to variables defined by the outer +Observe how the inner function refers to variables defined by the outer function. ```python From adb5c991abca91c9bbd38fafa9882d5cf0d2573e Mon Sep 17 00:00:00 2001 From: sina hosseinizad Date: Thu, 6 Aug 2020 12:46:03 +0200 Subject: [PATCH 63/89] add missing imports --- Notes/07_Advanced_Topics/03_Returning_functions.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Notes/07_Advanced_Topics/03_Returning_functions.md b/Notes/07_Advanced_Topics/03_Returning_functions.md index 896f8d593..c5f1eb935 100644 --- a/Notes/07_Advanced_Topics/03_Returning_functions.md +++ b/Notes/07_Advanced_Topics/03_Returning_functions.md @@ -86,6 +86,7 @@ Consider a function like this: ```python def after(seconds, func): + import time time.sleep(seconds) func() ``` @@ -110,6 +111,7 @@ def add(x, y): return do_add def after(seconds, func): + import time time.sleep(seconds) func() From 7d94852cdd4edf6904f8878c9f41bbf0ce9119de Mon Sep 17 00:00:00 2001 From: Zhi Li Date: Thu, 17 Sep 2020 09:46:30 -0400 Subject: [PATCH 64/89] Add missing link to built-in exceptions documentation --- Notes/03_Program_organization/03_Error_checking.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/03_Program_organization/03_Error_checking.md b/Notes/03_Program_organization/03_Error_checking.md index d4e4779d4..2c9938c5c 100644 --- a/Notes/03_Program_organization/03_Error_checking.md +++ b/Notes/03_Program_organization/03_Error_checking.md @@ -126,7 +126,7 @@ bar() There are about two-dozen built-in exceptions. Usually the name of the exception is indicative of what's wrong (e.g., a `ValueError` is raised because you supplied a bad value). This is not an -exhaustive list. Check the documentation for more. +exhaustive list. Check the [documentation](https://docs.python.org/3/library/exceptions.html) for more. ```python ArithmeticError From 9a3cd386fbef16bd3518c25dd8aa0e13e066739f Mon Sep 17 00:00:00 2001 From: David Beazley Date: Sun, 22 Nov 2020 13:20:19 -0600 Subject: [PATCH 65/89] Various typos fixed --- Notes/03_Program_organization/04_Modules.md | 4 ++-- Notes/06_Generators/03_Producers_consumers.md | 2 +- Notes/07_Advanced_Topics/03_Returning_functions.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Notes/03_Program_organization/04_Modules.md b/Notes/03_Program_organization/04_Modules.md index 22e7cf502..60a0866ec 100644 --- a/Notes/03_Program_organization/04_Modules.md +++ b/Notes/03_Program_organization/04_Modules.md @@ -212,8 +212,8 @@ not readily accessible from the current working directory. ## Exercises For this exercise involving modules, it is critically important to -make sure you are running Python in a proper environment. Modules are -usually when programmers encounter problems with the current working +make sure you are running Python in a proper environment. Modules +often present new programmers with problems related to the current working directory or with Python's path settings. For this course, it is assumed that you're writing all of your code in the `Work/` directory. For best results, you should make sure you're also in that directory diff --git a/Notes/06_Generators/03_Producers_consumers.md b/Notes/06_Generators/03_Producers_consumers.md index ffd7845b5..3245e5559 100644 --- a/Notes/06_Generators/03_Producers_consumers.md +++ b/Notes/06_Generators/03_Producers_consumers.md @@ -20,7 +20,7 @@ def follow(f): ... # Consumer -for line in follow(f): # Consumes vale from `yield` above +for line in follow(f): # Consumes value from `yield` above ... ``` diff --git a/Notes/07_Advanced_Topics/03_Returning_functions.md b/Notes/07_Advanced_Topics/03_Returning_functions.md index 30e6f0772..896f8d593 100644 --- a/Notes/07_Advanced_Topics/03_Returning_functions.md +++ b/Notes/07_Advanced_Topics/03_Returning_functions.md @@ -29,7 +29,7 @@ Adding 3 4 ### Local Variables -Observe how to inner function refers to variables defined by the outer +Observe how the inner function refers to variables defined by the outer function. ```python From 8449211f7de422db8332cf1339057c040ff45825 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Sun, 22 Nov 2020 13:29:54 -0600 Subject: [PATCH 66/89] Added link --- Notes/00_Setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/00_Setup.md b/Notes/00_Setup.md index eb5b94db5..4861578cc 100644 --- a/Notes/00_Setup.md +++ b/Notes/00_Setup.md @@ -86,7 +86,7 @@ exercises. Feel free to look at this if you need a hint. To get the most out of the course however, you should try to create your own solutions first. -[Contents](Contents.md) +[Contents](Contents.md) \| [Next (1 Introduction to Python)](01_Introduction/00_Overview.md) From 3cfe6a2d752e828ad09b30be03d78d6860c37b11 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Thu, 24 Dec 2020 19:48:55 -0600 Subject: [PATCH 67/89] Fixed wording --- Notes/01_Introduction/03_Numbers.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Notes/01_Introduction/03_Numbers.md b/Notes/01_Introduction/03_Numbers.md index 80f4e0a10..c8cca87ef 100644 --- a/Notes/01_Introduction/03_Numbers.md +++ b/Notes/01_Introduction/03_Numbers.md @@ -220,7 +220,8 @@ extra_payment = 1000 Make the program look at these variables and calculate the total paid appropriately. -How much will Dave pay if he pays an extra $1000/month for 4 years starting in year 5 of the mortgage? +How much will Dave pay if he pays an extra $1000/month for 4 years starting after the first +five years have already been paid? ### Exercise 1.10: Making a table From c8dc52231a7a827b16218268765c472f31ae34d7 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Sun, 31 Jan 2021 19:38:29 -0600 Subject: [PATCH 68/89] Fixed typo --- Notes/02_Working_with_data/06_List_comprehension.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/02_Working_with_data/06_List_comprehension.md b/Notes/02_Working_with_data/06_List_comprehension.md index 11e5ae9e3..66a037a2f 100644 --- a/Notes/02_Working_with_data/06_List_comprehension.md +++ b/Notes/02_Working_with_data/06_List_comprehension.md @@ -215,7 +215,7 @@ For example, this determines the set of unique stock names that appear in `portf ```python >>> names = { s['name'] for s in portfolio } >>> names -{ 'AA', 'GE', 'IBM', 'MSFT', 'CAT'] } +{ 'AA', 'GE', 'IBM', 'MSFT', 'CAT' } >>> ``` From eca8be369b465e6e85f366643cb91b5f0ae6b1e8 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Sun, 28 Mar 2021 09:39:53 -0500 Subject: [PATCH 69/89] Fix typo --- Notes/02_Working_with_data/03_Formatting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/02_Working_with_data/03_Formatting.md b/Notes/02_Working_with_data/03_Formatting.md index a3ec1e5f7..94b6198fe 100644 --- a/Notes/02_Working_with_data/03_Formatting.md +++ b/Notes/02_Working_with_data/03_Formatting.md @@ -115,7 +115,7 @@ modeled after the C `printf()` as well. *Note: This is the only formatting available on byte strings.* ```python ->>> b'%s has %n messages' % (b'Dave', 37) +>>> b'%s has %d messages' % (b'Dave', 37) b'Dave has 37 messages' >>> ``` From 92a8a73c078e7721d75fd0400e973b44bf7639b8 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Sun, 28 Mar 2021 09:42:14 -0500 Subject: [PATCH 70/89] Added example --- Notes/02_Working_with_data/02_Containers.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Notes/02_Working_with_data/02_Containers.md b/Notes/02_Working_with_data/02_Containers.md index 20ac55208..41833d4aa 100644 --- a/Notes/02_Working_with_data/02_Containers.md +++ b/Notes/02_Working_with_data/02_Containers.md @@ -195,12 +195,14 @@ unique = set(names) Additional set operations: ```python -names.add('CAT') # Add an item -names.remove('YHOO') # Remove an item - -s1 | s2 # Set union -s1 & s2 # Set intersection -s1 - s2 # Set difference +unique.add('CAT') # Add an item +unique.remove('YHOO') # Remove an item + +s1 = { 'a', 'b', 'c'} +s2 = { 'c', 'd' } +s1 | s2 # Set union { 'a', 'b', 'c', 'd' } +s1 & s2 # Set intersection { 'c' } +s1 - s2 # Set difference { 'a', 'b' } ``` ## Exercises From 9bbb256afa7ed6ff43733499446967780d257220 Mon Sep 17 00:00:00 2001 From: DrOculus90 <85500880+DrOculus90@users.noreply.github.com> Date: Mon, 7 Jun 2021 09:54:13 -0400 Subject: [PATCH 71/89] Update 03_Formatting.md Line 92: changed {:10s} to {:>10s} --- Notes/02_Working_with_data/03_Formatting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/02_Working_with_data/03_Formatting.md b/Notes/02_Working_with_data/03_Formatting.md index 94b6198fe..877a40627 100644 --- a/Notes/02_Working_with_data/03_Formatting.md +++ b/Notes/02_Working_with_data/03_Formatting.md @@ -89,7 +89,7 @@ keyword arguments. ```python >>> '{name:>10s} {shares:10d} {price:10.2f}'.format(name='IBM', shares=100, price=91.1) ' IBM 100 91.10' ->>> '{:10s} {:10d} {:10.2f}'.format('IBM', 100, 91.1) +>>> '{:>10s} {:10d} {:10.2f}'.format('IBM', 100, 91.1) ' IBM 100 91.10' >>> ``` From d55d6f74e7d2df37e79a48caf0ee1c9025596d5d Mon Sep 17 00:00:00 2001 From: DavideAG Date: Thu, 22 Jul 2021 16:03:49 +0200 Subject: [PATCH 72/89] Chapter 2.6 - Fixed typo in exercise 2.22 --- Notes/02_Working_with_data/06_List_comprehension.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/02_Working_with_data/06_List_comprehension.md b/Notes/02_Working_with_data/06_List_comprehension.md index 66a037a2f..08dd5d13f 100644 --- a/Notes/02_Working_with_data/06_List_comprehension.md +++ b/Notes/02_Working_with_data/06_List_comprehension.md @@ -207,7 +207,7 @@ Show how you could build a list of tuples `(name, shares)` where `name` and `sha >>> ``` -If you change the the square brackets (`[`,`]`) to curly braces (`{`, `}`), you get something known as a set comprehension. +If you change the square brackets (`[`,`]`) to curly braces (`{`, `}`), you get something known as a set comprehension. This gives you unique or distinct values. For example, this determines the set of unique stock names that appear in `portfolio`: From 79ea6a113b2ecaa55d923bd7bda9e613468794da Mon Sep 17 00:00:00 2001 From: David Beazley Date: Sun, 6 Feb 2022 19:55:07 -0600 Subject: [PATCH 73/89] Fix typo --- Notes/03_Program_organization/05_Main_module.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/03_Program_organization/05_Main_module.md b/Notes/03_Program_organization/05_Main_module.md index 0bcce5dae..c303e0fda 100644 --- a/Notes/03_Program_organization/05_Main_module.md +++ b/Notes/03_Program_organization/05_Main_module.md @@ -256,7 +256,7 @@ if __name__ == '__main__': In the file `report.py` add a `main()` function that accepts a list of command line options and produces the same output as before. You -should be able to run it interatively like this: +should be able to run it interactively like this: ```python >>> import report From cf0c74a9f94de853cb346771fdb7bbc3fd44a291 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Sat, 26 Nov 2022 09:22:24 -0600 Subject: [PATCH 74/89] Added noted about missing ex3.13 --- Notes/03_Program_organization/04_Modules.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Notes/03_Program_organization/04_Modules.md b/Notes/03_Program_organization/04_Modules.md index 60a0866ec..7cc8e7a54 100644 --- a/Notes/03_Program_organization/04_Modules.md +++ b/Notes/03_Program_organization/04_Modules.md @@ -316,6 +316,8 @@ and `read_prices()` functions to use the `parse_csv()` function. Use the interactive example at the start of this exercise as a guide. Afterwards, you should get exactly the same output as before. +### Exercise 3.13: Intentionally left blank (skip) + ### Exercise 3.14: Using more library imports In section 1, you wrote a program `pcost.py` that read a portfolio and computed its cost. From d74b29d25eb612712ff53ea5424d75b0f7a31738 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Sat, 26 Nov 2022 09:24:30 -0600 Subject: [PATCH 75/89] Fix broken links --- Notes/03_Program_organization/02_More_functions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Notes/03_Program_organization/02_More_functions.md b/Notes/03_Program_organization/02_More_functions.md index e169c1f98..f0649c7a2 100644 --- a/Notes/03_Program_organization/02_More_functions.md +++ b/Notes/03_Program_organization/02_More_functions.md @@ -338,7 +338,7 @@ follows: >>> ``` -An example of a column selector was given in [Exercise 2.23](../02_Working_with_data/06_List_comprehension). +An example of a column selector was given in [Exercise 2.23](../02_Working_with_data/06_List_comprehension.md). However, here’s one way to do it: ```python @@ -431,7 +431,7 @@ type-conversions to be applied to the returned data. For example: >>> ``` -You already explored this in [Exercise 2.24](../02_Working_with_data/07_Objects). +You already explored this in [Exercise 2.24](../02_Working_with_data/07_Objects.md). You'll need to insert the following fragment of code into your solution: ```python From a53642b9c791da292c728aa29ea8e99aaeb2b260 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Sat, 26 Nov 2022 09:25:59 -0600 Subject: [PATCH 76/89] Fix broken links --- Notes/03_Program_organization/02_More_functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Notes/03_Program_organization/02_More_functions.md b/Notes/03_Program_organization/02_More_functions.md index f0649c7a2..6d83591c6 100644 --- a/Notes/03_Program_organization/02_More_functions.md +++ b/Notes/03_Program_organization/02_More_functions.md @@ -209,7 +209,7 @@ of the function, it's better to use a class instead (more on this later). When you call a function, the argument variables are names that refer to the passed values. These values are NOT copies (see [section -2.7](../02_Working_with_data/07_Objects)). If mutable data types are +2.7](../02_Working_with_data/07_Objects.md)). If mutable data types are passed (e.g. lists, dicts), they can be modified *in-place*. ```python From db48a9c3d059e28a6de13180066e4ec0409a4142 Mon Sep 17 00:00:00 2001 From: David Beazley Date: Sat, 26 Nov 2022 09:29:04 -0600 Subject: [PATCH 77/89] Layout change --- README.md | 2 +- _layouts/default.html | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 21efa4540..5a4db0553 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Welcome! -When I first learned Python nearly 25 years ago, I was immediately +When I first learned Python nearly 27 years ago, I was immediately struck by how I could productively apply it to all sorts of messy work projects. Fast-forward a decade and I found myself teaching others the same fun. The result of that teaching is this course--A no-nonsense diff --git a/_layouts/default.html b/_layouts/default.html index 5ab571ce5..4381c49d1 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -24,7 +24,7 @@