diff --git a/ThinkPythonNotebooks.zip b/ThinkPythonNotebooks.zip index 4be25fae..e4202d4c 100644 Binary files a/ThinkPythonNotebooks.zip and b/ThinkPythonNotebooks.zip differ diff --git a/chapters/chap00.ipynb b/chapters/chap00.ipynb index b42d9c0e..e7c283c1 100644 --- a/chapters/chap00.ipynb +++ b/chapters/chap00.ipynb @@ -50,7 +50,7 @@ "\n", "Writing this book, I tried to be careful with the vocabulary.\n", "I define each term when it first appears.\n", - "And there is a glossary that the end of each chapter that reviews the terms that were introduced.\n", + "And there is a glossary at the end of each chapter that reviews the terms that were introduced.\n", "\n", "I also tried to be concise.\n", "The less mental effort it takes to read the book, the more capacity you will have for programming.\n", diff --git a/chapters/chap10.ipynb b/chapters/chap10.ipynb index e1de3afe..742da868 100644 --- a/chapters/chap10.ipynb +++ b/chapters/chap10.ipynb @@ -1364,7 +1364,7 @@ "id": "170f1deb", "metadata": {}, "source": [ - "### Ask an assistant\n", + "### Ask a virtual assistant\n", "\n", "In this chapter, I said the keys in a dictionary have to be hashable and I gave a short explanation. If you would like more details, ask a virtual assistant, \"Why do keys in Python dictionaries have to be hashable?\"\n", "\n", diff --git a/chapters/chap12.ipynb b/chapters/chap12.ipynb index 49c55ce7..f2d5d236 100644 --- a/chapters/chap12.ipynb +++ b/chapters/chap12.ipynb @@ -80,7 +80,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "4cd1c980", "metadata": { "tags": [] @@ -103,7 +103,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "52ebfe94", "metadata": { "tags": [] @@ -116,7 +116,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "id": "49cfc352", "metadata": { "tags": [] @@ -142,7 +142,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "id": "44e53ce6", "metadata": {}, "outputs": [], @@ -152,7 +152,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "id": "50d1fafa", "metadata": { "tags": [] @@ -173,7 +173,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 7, "id": "16d24028", "metadata": {}, "outputs": [], @@ -201,7 +201,7 @@ }, { "cell_type": "code", - "execution_count": 88, + "execution_count": 8, "id": "1668e6bd", "metadata": {}, "outputs": [], @@ -241,7 +241,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 9, "id": "ed5f0a43", "metadata": {}, "outputs": [], @@ -261,7 +261,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 10, "id": "a9df2aeb", "metadata": {}, "outputs": [], @@ -283,7 +283,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 11, "id": "b138b123", "metadata": {}, "outputs": [], @@ -305,7 +305,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 12, "id": "fe65df44", "metadata": {}, "outputs": [], @@ -324,7 +324,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 13, "id": "b47a87cf", "metadata": {}, "outputs": [], @@ -347,7 +347,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 14, "id": "348949be", "metadata": {}, "outputs": [], @@ -366,7 +366,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 15, "id": "06121901", "metadata": {}, "outputs": [], @@ -385,7 +385,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 16, "id": "881ed9f8", "metadata": {}, "outputs": [], @@ -403,7 +403,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 17, "id": "ab5d2fed", "metadata": {}, "outputs": [], @@ -421,7 +421,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 18, "id": "2fdfb936", "metadata": {}, "outputs": [], @@ -446,7 +446,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 19, "id": "3104d191", "metadata": {}, "outputs": [], @@ -474,7 +474,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 20, "id": "4fba7d1c", "metadata": {}, "outputs": [], @@ -502,7 +502,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 21, "id": "4be34c95", "metadata": {}, "outputs": [], @@ -525,7 +525,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 22, "id": "8efe7c4c", "metadata": {}, "outputs": [], @@ -543,7 +543,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 23, "id": "79c17341", "metadata": {}, "outputs": [], @@ -574,7 +574,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 24, "id": "838bcb4f", "metadata": {}, "outputs": [], @@ -593,7 +593,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 25, "id": "90c45e7e", "metadata": {}, "outputs": [], @@ -617,7 +617,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 26, "id": "e106be95", "metadata": {}, "outputs": [], @@ -635,7 +635,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 27, "id": "8101a510", "metadata": {}, "outputs": [], @@ -655,7 +655,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 28, "id": "c046117b", "metadata": { "tags": [] @@ -697,7 +697,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 29, "id": "edd8ff1c", "metadata": { "tags": [] @@ -717,7 +717,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 30, "id": "67ef3e08", "metadata": {}, "outputs": [], @@ -735,7 +735,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 31, "id": "471d58e9", "metadata": {}, "outputs": [], @@ -755,7 +755,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 32, "id": "4d4c3538", "metadata": {}, "outputs": [], @@ -778,7 +778,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 33, "id": "8b42e014", "metadata": {}, "outputs": [], @@ -796,7 +796,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 34, "id": "f48be152", "metadata": {}, "outputs": [], @@ -817,7 +817,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 35, "id": "5716f967", "metadata": {}, "outputs": [], @@ -838,7 +838,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 36, "id": "b37219f5", "metadata": {}, "outputs": [], @@ -880,7 +880,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 37, "id": "75b548a9", "metadata": {}, "outputs": [], @@ -890,7 +890,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 38, "id": "2bfa31ae", "metadata": { "tags": [] @@ -913,7 +913,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 39, "id": "6f5d5c1c", "metadata": {}, "outputs": [], @@ -932,7 +932,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 40, "id": "1445068b", "metadata": {}, "outputs": [], @@ -952,7 +952,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 41, "id": "4fc47ecd", "metadata": { "tags": [] @@ -974,7 +974,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 42, "id": "91ae9d4c", "metadata": {}, "outputs": [], @@ -993,7 +993,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 43, "id": "8bf595c1", "metadata": {}, "outputs": [], @@ -1016,7 +1016,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 44, "id": "22953b65", "metadata": {}, "outputs": [], @@ -1034,7 +1034,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 45, "id": "1c7cdf4d", "metadata": {}, "outputs": [], @@ -1052,7 +1052,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 46, "id": "a7a3aa42", "metadata": {}, "outputs": [], @@ -1071,7 +1071,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 47, "id": "c4286fb3", "metadata": {}, "outputs": [], @@ -1111,7 +1111,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 48, "id": "d8ee02f6", "metadata": {}, "outputs": [], @@ -1131,7 +1131,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 49, "id": "bfdb1de1", "metadata": {}, "outputs": [], @@ -1158,7 +1158,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 50, "id": "2e73df79", "metadata": {}, "outputs": [], @@ -1176,7 +1176,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 51, "id": "495ad429", "metadata": {}, "outputs": [], @@ -1206,7 +1206,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 52, "id": "c1224061", "metadata": {}, "outputs": [], @@ -1228,7 +1228,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 53, "id": "4296485a", "metadata": {}, "outputs": [], @@ -1247,7 +1247,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 54, "id": "e03fd803", "metadata": { "tags": [] @@ -1259,7 +1259,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 55, "id": "f6ee1840", "metadata": {}, "outputs": [], @@ -1282,7 +1282,7 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 56, "id": "d6c65d79", "metadata": {}, "outputs": [], @@ -1312,7 +1312,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 57, "id": "3171d592", "metadata": {}, "outputs": [], @@ -1335,7 +1335,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 58, "id": "3321e6a4", "metadata": {}, "outputs": [], @@ -1353,7 +1353,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 59, "id": "e4e55c71", "metadata": {}, "outputs": [], @@ -1372,7 +1372,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 60, "id": "f25dcb5e", "metadata": {}, "outputs": [], @@ -1391,7 +1391,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 61, "id": "990354a0", "metadata": {}, "outputs": [], @@ -1413,7 +1413,7 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 62, "id": "b9371452", "metadata": {}, "outputs": [], @@ -1441,7 +1441,7 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 63, "id": "8c3f45c2", "metadata": {}, "outputs": [], @@ -1464,7 +1464,7 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 64, "id": "641990a3", "metadata": {}, "outputs": [], @@ -1487,7 +1487,7 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 65, "id": "9322a49a", "metadata": {}, "outputs": [], @@ -1509,7 +1509,7 @@ }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 66, "id": "45a60c52", "metadata": {}, "outputs": [], @@ -1533,7 +1533,7 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 67, "id": "3e86102c", "metadata": { "tags": [] @@ -1553,7 +1553,7 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 68, "id": "e49d52f7", "metadata": {}, "outputs": [], @@ -1590,7 +1590,7 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 69, "id": "15108884", "metadata": {}, "outputs": [], @@ -1602,7 +1602,7 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 70, "id": "747a41be", "metadata": { "tags": [] @@ -1626,7 +1626,7 @@ }, { "cell_type": "code", - "execution_count": 73, + "execution_count": 71, "id": "5a4682dc", "metadata": {}, "outputs": [], @@ -1647,7 +1647,7 @@ }, { "cell_type": "code", - "execution_count": 74, + "execution_count": 72, "id": "36ee0f76", "metadata": {}, "outputs": [], @@ -1782,7 +1782,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 73, "id": "05752b6d", "metadata": { "tags": [] @@ -1807,7 +1807,7 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": 74, "id": "a4365ac0", "metadata": {}, "outputs": [], @@ -1850,7 +1850,7 @@ }, { "cell_type": "code", - "execution_count": 76, + "execution_count": 75, "id": "f38a61ff", "metadata": {}, "outputs": [], @@ -1860,7 +1860,7 @@ }, { "cell_type": "code", - "execution_count": 77, + "execution_count": 76, "id": "d047e546", "metadata": {}, "outputs": [], @@ -1880,7 +1880,7 @@ }, { "cell_type": "code", - "execution_count": 78, + "execution_count": 77, "id": "6b8932ee", "metadata": { "tags": [] @@ -1908,7 +1908,7 @@ }, { "cell_type": "code", - "execution_count": 79, + "execution_count": 78, "id": "44c3f0d8", "metadata": { "tags": [] @@ -1932,7 +1932,7 @@ }, { "cell_type": "code", - "execution_count": 80, + "execution_count": 79, "id": "3fcf85f4", "metadata": {}, "outputs": [], @@ -1950,7 +1950,7 @@ }, { "cell_type": "code", - "execution_count": 81, + "execution_count": 80, "id": "d9e554e3", "metadata": {}, "outputs": [], @@ -1975,7 +1975,7 @@ }, { "cell_type": "code", - "execution_count": 82, + "execution_count": 81, "id": "8c2ee21c", "metadata": { "tags": [] @@ -2003,7 +2003,7 @@ }, { "cell_type": "code", - "execution_count": 83, + "execution_count": 82, "id": "b13384e3", "metadata": { "tags": [] @@ -2023,7 +2023,7 @@ }, { "cell_type": "code", - "execution_count": 84, + "execution_count": 83, "id": "62c2177f", "metadata": {}, "outputs": [], @@ -2057,7 +2057,7 @@ }, { "cell_type": "code", - "execution_count": 85, + "execution_count": 84, "id": "64e11f26", "metadata": { "tags": [] @@ -2081,7 +2081,7 @@ }, { "cell_type": "code", - "execution_count": 86, + "execution_count": 85, "id": "fe2d93fa", "metadata": {}, "outputs": [], @@ -2109,7 +2109,7 @@ }, { "cell_type": "code", - "execution_count": 89, + "execution_count": 86, "id": "22210a5c", "metadata": {}, "outputs": [], diff --git a/chapters/chap13.ipynb b/chapters/chap13.ipynb index ba90420d..fe8f516a 100644 --- a/chapters/chap13.ipynb +++ b/chapters/chap13.ipynb @@ -753,6 +753,18 @@ "db" ] }, + { + "cell_type": "markdown", + "id": "47685eb7", + "metadata": { + "tags": [] + }, + "source": [ + "If you get an error like `db type could not be determined`, the most likely cause is that a file with the same name already exists but is not a valid shelve database (for example, it may be corrupted or created by something else).\n", + "\n", + "In that case, the simplest solution is to delete the existing file and run the code again so that `shelve.open` can create a new database." + ] + }, { "cell_type": "markdown", "id": "0e4a2fb3", diff --git a/chapters/chap15.ipynb b/chapters/chap15.ipynb index 52fb9c86..f7dfa60f 100644 --- a/chapters/chap15.ipynb +++ b/chapters/chap15.ipynb @@ -373,7 +373,7 @@ "id": "e6a18c76", "metadata": {}, "source": [ - "Now that we have `Time.from_seconds`, we can use it to write `add_time` as a method.\n", + "Now that we have `Time.int_to_time`, we can use it to write `add_time` as a method.\n", "Here's the function from the previous chapter." ] }, @@ -409,7 +409,7 @@ "\n", " def add_time(self, hours, minutes, seconds):\n", " duration = make_time(hours, minutes, seconds)\n", - " seconds = time_to_int(self) + time_to_int(duration)\n", + " seconds = Time.time_to_int(self) + Time.time_to_int(duration)\n", " return Time.int_to_time(seconds)" ] }, @@ -431,7 +431,7 @@ "outputs": [], "source": [ "end = start.add_time(1, 32, 0)\n", - "print_time(end)" + "end.print_time()" ] }, { @@ -836,7 +836,7 @@ "\n", " def is_after(self, other):\n", " assert self.is_valid(), 'self is not a valid Time'\n", - " assert other.is_valid(), 'self is not a valid Time'\n", + " assert other.is_valid(), 'other is not a valid Time'\n", " return self.time_to_int() > other.time_to_int()" ] }, @@ -924,7 +924,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "id": "3115ea33", "metadata": { "tags": [] @@ -960,7 +960,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 37, "id": "133d7679", "metadata": {}, "outputs": [], @@ -992,7 +992,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 38, "id": "3c9f3777-4869-481e-9f4e-4223d6028913", "metadata": {}, "outputs": [], @@ -1012,7 +1012,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 39, "id": "fd4b2521-aa71-45da-97eb-ce62ce2714ad", "metadata": { "tags": [] @@ -1025,7 +1025,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 40, "id": "ee3f1294-cad1-406b-a574-045ad2b84294", "metadata": { "tags": [] @@ -1038,7 +1038,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 41, "id": "ac093f7b-83cf-4488-8842-5c71bcfa35ec", "metadata": { "tags": [] @@ -1050,7 +1050,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 42, "id": "7e7cb5e1-631f-4b1e-874f-eb16d4792625", "metadata": { "tags": [] diff --git a/chapters/chap16.ipynb b/chapters/chap16.ipynb index 57f3d417..eb84e1ca 100644 --- a/chapters/chap16.ipynb +++ b/chapters/chap16.ipynb @@ -234,7 +234,7 @@ "id": "a7a635ee", "metadata": {}, "source": [ - "In the same way that the built in function `sort` modifies a list, and the `sorted` function creates a new list, now we have a `translate` method that modifies a `Point` and a `translated` method that creates a new one.\n", + "In the same way that the `sort` method modifies a list and the `sorted` function creates a new list, now we have a `translate` method that modifies a `Point` and a `translated` method that creates a new one.\n", "\n", "Here's an example:" ] diff --git a/chapters/chap18.ipynb b/chapters/chap18.ipynb index 41d5fc1a..30278222 100644 --- a/chapters/chap18.ipynb +++ b/chapters/chap18.ipynb @@ -1661,7 +1661,7 @@ "id": "07be77f3", "metadata": {}, "source": [ - "In this example, the value of `kwargs` is printed, but otherwise is has no effect.\n", + "In this example, the value of `kwargs` is printed, but otherwise it has no effect.\n", "\n", "But the `**` operator can also be used in an argument list to unpack a dictionary.\n", "For example, here's a version of `mean` that packs any keyword arguments it gets and then unpacks them as keyword arguments for `sum`."