diff --git a/ThinkPythonNotebooks.zip b/ThinkPythonNotebooks.zip index cb57fd70..e4202d4c 100644 Binary files a/ThinkPythonNotebooks.zip and b/ThinkPythonNotebooks.zip differ diff --git a/blank/chap00.ipynb b/blank/chap00.ipynb index a21a38af..55b62c27 100644 --- a/blank/chap00.ipynb +++ b/blank/chap00.ipynb @@ -217,6 +217,22 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { @@ -235,7 +251,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.14" + "version": "3.10.11" } }, "nbformat": 4, diff --git a/blank/chap01.ipynb b/blank/chap01.ipynb index 1fb365f7..7b758f07 100644 --- a/blank/chap01.ipynb +++ b/blank/chap01.ipynb @@ -161,9 +161,9 @@ "source": [ "Notice that the result of the division is `42.0` rather than `42`. That's because there are two types of numbers in Python: \n", "\n", - "* **integers**, which represent whole numbers, and \n", + "* **integers**, which represent numbers with no fractional or decimal part, and \n", "\n", - "* **floating-point numbers**, which represent numbers with a decimal point.\n", + "* **floating-point numbers**, which represent integers and numbers with a decimal point.\n", "\n", "If you add, subtract, or multiply two integers, the result is an integer.\n", "But if you divide two integers, the result is a floating-point number.\n", @@ -311,7 +311,7 @@ "## Arithmetic functions\n", "\n", "In addition to the arithmetic operators, Python provides a few **functions** that work with numbers.\n", - "For example, the `round` function takes a floating-point number and rounds it off to the nearest whole number." + "For example, the `round` function takes a floating-point number and rounds it off to the nearest integer." ] }, { @@ -533,7 +533,7 @@ "source": [ "The other arithmetic operators don't work with strings.\n", "\n", - "Python provides a function called `len` that computes the length of a string.`" + "Python provides a function called `len` that computes the length of a string." ] }, { @@ -877,10 +877,10 @@ "A symbol, like `+` and `*`, that denotes an arithmetic operation like addition or multiplication.\n", "\n", "**integer:**\n", - "A type that represents whole numbers.\n", + "A type that represents numbers with no fractional or decimal part.\n", "\n", "**floating-point:**\n", - "A type that represents numbers with fractional parts.\n", + "A type that represents integers and numbers with decimal parts.\n", "\n", "**integer division:**\n", "An operator, `//`, that divides two numbers and rounds down to an integer.\n", @@ -979,7 +979,7 @@ "\n", "* I also mentioned the order of operations. For more details, ask \"What is the order of operations in Python?\"\n", "\n", - "* The `round` function, which we used to round a floating-point number to the nearest whole number, can take a second argument. Try asking \"What are the arguments of the round function?\" or \"How do I round pi off to three decimal places?\"\n", + "* The `round` function, which we used to round a floating-point number to the nearest integer, can take a second argument. Try asking \"What are the arguments of the round function?\" or \"How do I round pi off to three decimal places?\"\n", "\n", "* There's one more arithmetic operator I didn't mention; try asking \"What is the modulus operator in Python?\"" ] @@ -1162,6 +1162,22 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { diff --git a/blank/chap02.ipynb b/blank/chap02.ipynb index ca7c116c..345e793b 100644 --- a/blank/chap02.ipynb +++ b/blank/chap02.ipynb @@ -1096,6 +1096,22 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { diff --git a/blank/chap03.ipynb b/blank/chap03.ipynb index 7bd3423e..a2b67664 100644 --- a/blank/chap03.ipynb +++ b/blank/chap03.ipynb @@ -509,13 +509,13 @@ "frame2 = make_frame(d2, name='cat_twice', dy=-0.3, \n", " offsetx=0.03, loc='left')\n", "\n", - "d3 = dict(s = line1+line2)\n", + "d3 = dict(string=line1+line2)\n", "frame3 = make_frame(d3, name='print_twice', \n", - " offsetx=-0.28, offsety=-0.3, loc='left')\n", + " offsetx=0.04, offsety=-0.3, loc='left')\n", "\n", "d4 = {\"?\": line1+line2}\n", "frame4 = make_frame(d4, name='print', \n", - " offsetx=-0.28, offsety=0, loc='left')\n", + " offsetx=-0.22, offsety=0, loc='left')\n", "\n", "stack = Stack([frame1, frame2, frame3, frame4], dy=-0.8)" ] @@ -532,10 +532,10 @@ "from diagram import diagram, adjust\n", "\n", "\n", - "width, height, x, y = [3.8, 2.91, 1.15, 2.66]\n", + "width, height, x, y = [3.77, 2.9, 1.1, 2.65]\n", "ax = diagram(width, height)\n", "bbox = stack.draw(ax, x, y)\n", - "#adjust(x, y, bbox)" + "# adjust(x, y, bbox)" ] }, { @@ -955,6 +955,22 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { diff --git a/blank/chap04.ipynb b/blank/chap04.ipynb index 6b5fca95..23e5490e 100644 --- a/blank/chap04.ipynb +++ b/blank/chap04.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "id": "df64b7da", "metadata": { "tags": [] @@ -22,7 +22,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "id": "320fc8bc", "metadata": { "tags": [] @@ -55,7 +55,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "id": "8f5a8a45", "metadata": {}, "outputs": [], @@ -71,7 +71,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "id": "b3f255cd", "metadata": {}, "outputs": [], @@ -94,7 +94,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "id": "234fde81", "metadata": {}, "outputs": [], @@ -110,7 +110,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "id": "1e768880", "metadata": {}, "outputs": [], @@ -127,7 +127,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "id": "6d874b03", "metadata": {}, "outputs": [], @@ -144,7 +144,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "id": "1bb57a0c", "metadata": {}, "outputs": [], @@ -171,7 +171,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "id": "9a9e455f", "metadata": {}, "outputs": [], @@ -187,7 +187,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "id": "cc27ad66", "metadata": {}, "outputs": [], @@ -207,7 +207,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "id": "ad5f1128", "metadata": {}, "outputs": [], @@ -223,7 +223,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 13, "id": "193bbe5e", "metadata": {}, "outputs": [], @@ -243,7 +243,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 14, "id": "def8a5f1", "metadata": {}, "outputs": [], @@ -259,7 +259,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 15, "id": "b283e795", "metadata": {}, "outputs": [], @@ -273,12 +273,12 @@ "Adding a parameter to a function is called **generalization** because it makes the function more general: with the previous version, the square is always the same size; with this version it can be any size.\n", "\n", "If we add another parameter, we can make it even more general.\n", - "The following function draws regular polygons with a given of sides." + "The following function draws regular polygons with a given number of sides." ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 16, "id": "171974ed", "metadata": {}, "outputs": [], @@ -296,7 +296,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 17, "id": "71f7d9d2", "metadata": {}, "outputs": [], @@ -313,7 +313,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 18, "id": "8ff2a5f4", "metadata": { "tags": [] @@ -346,7 +346,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 19, "id": "7f2a5f28", "metadata": {}, "outputs": [], @@ -368,7 +368,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 20, "id": "75258056", "metadata": {}, "outputs": [], @@ -404,7 +404,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 21, "id": "381edd23", "metadata": {}, "outputs": [], @@ -422,7 +422,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 22, "id": "2f4eecc0", "metadata": {}, "outputs": [], @@ -438,7 +438,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 23, "id": "539466f6", "metadata": {}, "outputs": [], @@ -456,7 +456,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 24, "id": "8e09f456", "metadata": {}, "outputs": [], @@ -473,7 +473,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 25, "id": "80d6eadd", "metadata": {}, "outputs": [], @@ -505,7 +505,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 26, "id": "1571ee71", "metadata": { "tags": [] @@ -515,7 +515,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 27, "id": "f4e37360", "metadata": { "tags": [] @@ -576,7 +576,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 28, "id": "baf964ba", "metadata": {}, "outputs": [], @@ -592,7 +592,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 29, "id": "e2e006d5", "metadata": {}, "outputs": [], @@ -621,7 +621,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 30, "id": "b68f3682", "metadata": {}, "outputs": [], @@ -718,7 +718,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 31, "id": "9f94061e", "metadata": { "tags": [] @@ -742,7 +742,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 32, "id": "6f9a0106", "metadata": {}, "outputs": [], @@ -761,7 +761,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 33, "id": "c54ba660", "metadata": {}, "outputs": [], @@ -779,7 +779,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 34, "id": "1311ee08", "metadata": { "tags": [] @@ -792,14 +792,14 @@ "id": "8b8faaf6", "metadata": {}, "source": [ - "## Exercise\n", + "### Exercise\n", "\n", "Write a function called `rhombus` that draws a rhombus with a given side length and a given interior angle. For example, here's a rhombus with side length `50` and an interior angle of `60` degrees." ] }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 35, "id": "3db6f106", "metadata": {}, "outputs": [], @@ -817,7 +817,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 36, "id": "1d845de9", "metadata": { "tags": [] @@ -837,7 +837,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 37, "id": "895005cb", "metadata": {}, "outputs": [], @@ -845,7 +845,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 38, "id": "7e7d34b0", "metadata": {}, "outputs": [], @@ -853,7 +853,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 39, "id": "481396f9", "metadata": {}, "outputs": [], @@ -871,7 +871,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 40, "id": "c8dfebc9", "metadata": { "tags": [] @@ -881,19 +881,21 @@ }, { "cell_type": "markdown", - "id": "feae252c", + "id": "991ab59d", "metadata": {}, "source": [ "### Exercise\n", "\n", "Write an appropriately general set of functions that can draw shapes like this.\n", "\n", + "![](https://github.com/AllenDowney/ThinkPython/raw/v3/jupyturtle_pie.png)\n", + "\n", "Hint: Write a function called `triangle` that draws one triangular segment, and then a function called `draw_pie` that uses `triangle`." ] }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 41, "id": "8be6442e", "metadata": {}, "outputs": [], @@ -901,7 +903,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 42, "id": "be1b7ed8", "metadata": {}, "outputs": [], @@ -919,7 +921,17 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": null, + "id": "c519ca39", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 51, "id": "89ce198a", "metadata": { "tags": [] @@ -929,19 +941,21 @@ }, { "cell_type": "markdown", - "id": "7c665dd1", + "id": "9c78b76f", "metadata": {}, "source": [ "### Exercise\n", "\n", "Write an appropriately general set of functions that can draw flowers like this.\n", "\n", + "![](https://github.com/AllenDowney/ThinkPython/raw/v3/jupyturtle_flower.png)\n", + "\n", "Hint: Use `arc` to write a function called `petal` that draws one flower petal." ] }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 44, "id": "0f0e7498", "metadata": {}, "outputs": [], @@ -949,7 +963,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 45, "id": "6c0d0bff", "metadata": {}, "outputs": [], @@ -972,7 +986,17 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": null, + "id": "04193da5", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 53, "id": "4cfea3b0", "metadata": { "tags": [] @@ -1029,7 +1053,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 47, "id": "46d3151c", "metadata": {}, "outputs": [], @@ -1037,19 +1061,27 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 48, "id": "186c7fbc", "metadata": {}, "outputs": [], "source": [] }, { - "cell_type": "code", - "execution_count": null, - "id": "979f5ad4", - "metadata": {}, - "outputs": [], - "source": [] + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { diff --git a/blank/chap05.ipynb b/blank/chap05.ipynb index b27f183d..9f9ad192 100644 --- a/blank/chap05.ipynb +++ b/blank/chap05.ipynb @@ -1506,6 +1506,22 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { diff --git a/blank/chap06.ipynb b/blank/chap06.ipynb index b35c34b8..7fadc4ef 100644 --- a/blank/chap06.ipynb +++ b/blank/chap06.ipynb @@ -1654,6 +1654,22 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { diff --git a/blank/chap07.ipynb b/blank/chap07.ipynb index e2855cca..22ea459e 100644 --- a/blank/chap07.ipynb +++ b/blank/chap07.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "f0c8eb18", "metadata": { "tags": [] @@ -50,7 +50,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "6b8569b8-1576-45d2-99f6-c7a2c7e100c4", "metadata": {}, "outputs": [], @@ -68,7 +68,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "6cb5b573-601c-42f5-a940-f1a4d244f990", "metadata": {}, "outputs": [], @@ -87,7 +87,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "id": "7040a890-6619-4ad2-b0bf-b094a5a0e43d", "metadata": {}, "outputs": [], @@ -103,7 +103,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "id": "40fd553c-693c-4ffc-8e49-1d7de3c4d4a7", "metadata": {}, "outputs": [], @@ -119,7 +119,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "id": "8a34174b-5a77-482a-8480-14cfdff16339", "metadata": {}, "outputs": [], @@ -135,7 +135,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "id": "0909121d-5218-49ca-b03e-258206f00e40", "metadata": {}, "outputs": [], @@ -151,7 +151,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "id": "3c4d8138-ddf6-46fe-a940-a7042617ceb1", "metadata": {}, "outputs": [], @@ -159,7 +159,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "id": "5c463051-b737-49ab-a1d7-4be66fd8331f", "metadata": {}, "outputs": [], @@ -188,7 +188,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 10, "id": "a7b7ac52-64a6-4dd9-98f5-b772a5e0f161", "metadata": { "tags": [] @@ -207,7 +207,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 11, "id": "1ad13ce7-99be-4412-8e0b-978fe6de25f2", "metadata": {}, "outputs": [], @@ -223,7 +223,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 12, "id": "dc2054e6-d8e8-4a06-a1ea-5cfcf4ccf1e0", "metadata": {}, "outputs": [], @@ -246,7 +246,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 13, "id": "eaea1520-0fb3-4ef3-be6e-9e1cdcccf39f", "metadata": {}, "outputs": [], @@ -262,7 +262,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 14, "id": "f602bfb6-7a93-4fb8-ade6-6784155a6f1a", "metadata": {}, "outputs": [], @@ -281,7 +281,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 15, "id": "cf3b8b7e-5fc7-4bb1-b628-09277bdc5a0d", "metadata": { "tags": [] @@ -314,7 +314,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 16, "id": "6bf8a104", "metadata": {}, "outputs": [], @@ -330,7 +330,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 17, "id": "0fe7ae60", "metadata": {}, "outputs": [], @@ -346,7 +346,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 18, "id": "8a09bc24", "metadata": { "tags": [] @@ -356,7 +356,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 19, "id": "36a45674-7f41-4850-98f1-2548574ce958", "metadata": { "tags": [] @@ -378,7 +378,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 20, "id": "ba2ab90b", "metadata": { "tags": [] @@ -388,7 +388,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 21, "id": "88496dc4", "metadata": {}, "outputs": [], @@ -406,9 +406,11 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 22, "id": "4a0c46b9", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [] }, @@ -423,7 +425,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 23, "id": "2220d826", "metadata": {}, "outputs": [], @@ -441,7 +443,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 24, "id": "d8e1ac5a", "metadata": {}, "outputs": [], @@ -467,7 +469,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 25, "id": "0afd8f88", "metadata": {}, "outputs": [], @@ -485,7 +487,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 26, "id": "8686b2eb-c610-4d29-a942-2ef8f53e5e36", "metadata": {}, "outputs": [], @@ -503,7 +505,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 27, "id": "89a05280", "metadata": {}, "outputs": [], @@ -519,7 +521,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 28, "id": "9d29b5e9", "metadata": {}, "outputs": [], @@ -535,7 +537,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 29, "id": "304dfd86", "metadata": {}, "outputs": [], @@ -562,7 +564,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 30, "id": "fe6431b7", "metadata": {}, "outputs": [], @@ -578,7 +580,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 31, "id": "85d3fba6", "metadata": {}, "outputs": [], @@ -594,7 +596,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 32, "id": "2d653847", "metadata": {}, "outputs": [], @@ -611,7 +613,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 33, "id": "a92a81bc", "metadata": {}, "outputs": [], @@ -627,7 +629,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 34, "id": "d15f83a4", "metadata": {}, "outputs": [], @@ -643,7 +645,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 35, "id": "e7958af4", "metadata": {}, "outputs": [], @@ -651,7 +653,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 36, "id": "020a57a7", "metadata": {}, "outputs": [], @@ -659,7 +661,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 37, "id": "0b979b20", "metadata": {}, "outputs": [], @@ -678,7 +680,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 38, "id": "bd29ff63", "metadata": {}, "outputs": [], @@ -694,7 +696,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 39, "id": "9369fb05", "metadata": {}, "outputs": [], @@ -710,7 +712,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 40, "id": "eb32713a", "metadata": {}, "outputs": [], @@ -721,12 +723,12 @@ "id": "b2acc611", "metadata": {}, "source": [ - "`uses_only` converts `word` and `letters` to lowercase, so it works with any combination of cases. " + "`uses_any` converts `word` and `letters` to lowercase, so it works with any combination of cases. " ] }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 41, "id": "7e65a9fb", "metadata": {}, "outputs": [], @@ -760,7 +762,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 42, "id": "3982e7d3", "metadata": {}, "outputs": [], @@ -784,7 +786,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 43, "id": "40ef00d3", "metadata": {}, "outputs": [], @@ -801,7 +803,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 44, "id": "f37cfd36", "metadata": {}, "outputs": [], @@ -822,7 +824,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 45, "id": "58c916cc", "metadata": {}, "outputs": [], @@ -838,7 +840,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 46, "id": "7a325745", "metadata": {}, "outputs": [], @@ -905,7 +907,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "id": "bc58db59", "metadata": { "tags": [] @@ -1292,18 +1294,34 @@ { "cell_type": "code", "execution_count": 71, - "id": "6980de57", + "id": "a3ea747d", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", - "execution_count": null, - "id": "102df097", + "execution_count": 72, + "id": "6980de57", "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { diff --git a/blank/chap08.ipynb b/blank/chap08.ipynb index e137ddc3..00a2a91d 100644 --- a/blank/chap08.ipynb +++ b/blank/chap08.ipynb @@ -1303,10 +1303,7 @@ "Replacement of a string, or part of a string, with another string.\n", "\n", "**shell command:**\n", - "A statement in a shell language, which is a language used to interact with an operating system.\n", - "\n", - "**raw string:**\n", - "A Python string that is preceded by the letter `r`, which indicates that backslashes that appear in the string should not be considered part of a special sequence." + "A statement in a shell language, which is a language used to interact with an operating system." ] }, { @@ -1358,7 +1355,7 @@ "\n", "And if you want to see something more complicated, try asking for a regular expression that matches any legal URL.\n", "\n", - "A regular expression often has the letter `r` before the quotation mark, which indicates that it is a **raw string**.\n", + "A regular expression often has the letter `r` before the quotation mark, which indicates that it is a \"raw string\".\n", "For more information, ask a virtual assistant, \"What is a raw string in Python?\"" ] }, @@ -1445,12 +1442,12 @@ "Each attempt has to be recognized as a word, not including proper nouns.\n", "After each attempt, you get information about which of the letters you guessed appear in the target word, and which ones are in the correct position.\n", "\n", - "For example, suppose the target word is `MOWER` and you guess `TRIED`. You would learn that `E` is in the word and in the correct position, `R` is in the word but not in the correct position, and `T`, `I`, and `D` are not in the word.\n", + "For example, suppose the target word is `MOWER` and you guess `TRIED`.\n", + "You would learn that `E` is in the word and in the correct position, `R` is in the word but not in the correct position, and `T`, `I`, and `D` are not in the word.\n", "\n", "As a different example, suppose you have guessed the words `SPADE` and `CLERK`, and you've learned that `E` is in the word, but not in either of those positions, and none of the other letters appear in the word.\n", - "\n", "Of the words in the word list, how many could be the target word?\n", - "Write a function called `check_word` that takes a five-letter word and checks whether it could be the target word." + "Write a function called `check_word` that takes a five-letter word and checks whether it could be the target word, given these guesses." ] }, { @@ -1537,8 +1534,9 @@ "\n", "In particular, he says it is \"shameless in its repetition of the same adjective,\" and mentions in particular the number of times \"its characters either shudder or turn pale.\"\n", "\n", - "To see whether his objection is valid, let's count the number number of times the word `pale` appears in any form, including `pale`, `pales`, `paled`, and `paleness`, as well as the related word `pallor`. \n", - "Use a single regular expression that matches all of these words and no others." + "To see whether his objection is valid, let's count the number number of lines that contain the word `pale` in any form, including `pale`, `pales`, `paled`, and `paleness`, as well as the related word `pallor`. \n", + "Use a single regular expression that matches any of these words.\n", + "As an additional challenge, make sure that it doesn't match any other words, like `impale` -- you might want to ask a virtual assistant for help." ] }, { @@ -1583,7 +1581,7 @@ }, { "cell_type": "code", - "execution_count": 89, + "execution_count": 83, "id": "08294921", "metadata": {}, "outputs": [], @@ -1591,29 +1589,45 @@ }, { "cell_type": "code", - "execution_count": 90, + "execution_count": 84, "id": "3eb8f83f", "metadata": {}, "outputs": [], "source": [] }, + { + "cell_type": "code", + "execution_count": 85, + "id": "b6bffe8a", + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", - "id": "71d2148f", + "id": "7db56337", "metadata": { "tags": [] }, "source": [ - "By my count, these words appear `223` times in a book that contains about `461,000` words. Mr. Eco might have a point." + "By this count, these words appear on `223` lines of the book, so Mr. Eco might have a point." ] }, { - "cell_type": "code", - "execution_count": null, - "id": "32d539d9", - "metadata": {}, - "outputs": [], - "source": [] + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { diff --git a/blank/chap09.ipynb b/blank/chap09.ipynb index 45213143..c4cae84c 100644 --- a/blank/chap09.ipynb +++ b/blank/chap09.ipynb @@ -1633,6 +1633,22 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { diff --git a/blank/chap10.ipynb b/blank/chap10.ipynb index 23c31578..56d77c9f 100644 --- a/blank/chap10.ipynb +++ b/blank/chap10.ipynb @@ -1008,7 +1008,7 @@ "\n", "As you work with bigger datasets it can become unwieldy to debug by printing and checking the output by hand. Here are some suggestions for debugging large datasets:\n", "\n", - "1) Scale down the input: If possible, reduce the size of the dataset. For example if the\n", + "1. Scale down the input: If possible, reduce the size of the dataset. For example if the\n", " program reads a text file, start with just the first 10 lines, or\n", " with the smallest example you can find. You can either edit the\n", " files themselves, or (better) modify the program so it reads only\n", @@ -1492,6 +1492,22 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { diff --git a/blank/chap11.ipynb b/blank/chap11.ipynb index 916cd437..d80bc234 100644 --- a/blank/chap11.ipynb +++ b/blank/chap11.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "id": "295ac6d7", "metadata": { "tags": [] @@ -54,7 +54,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "id": "fb0bdca2", "metadata": {}, "outputs": [], @@ -70,7 +70,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "id": "5a6da881", "metadata": {}, "outputs": [], @@ -86,7 +86,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "id": "e2596ca7", "metadata": {}, "outputs": [], @@ -102,7 +102,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "id": "a0d350a6", "metadata": {}, "outputs": [], @@ -119,7 +119,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "id": "c9100ee4", "metadata": {}, "outputs": [], @@ -136,7 +136,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "id": "44bd3d83", "metadata": {}, "outputs": [], @@ -155,7 +155,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "id": "92e55b2c", "metadata": {}, "outputs": [], @@ -171,7 +171,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "id": "38ee5c2a", "metadata": {}, "outputs": [], @@ -187,7 +187,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "id": "2e0e311a", "metadata": {}, "outputs": [], @@ -203,7 +203,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "id": "8bb7d715", "metadata": {}, "outputs": [], @@ -219,7 +219,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 13, "id": "e653e00f", "metadata": {}, "outputs": [], @@ -235,7 +235,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 14, "id": "8969188d", "metadata": {}, "outputs": [], @@ -251,7 +251,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 15, "id": "65d7ebaa", "metadata": {}, "outputs": [], @@ -277,7 +277,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 16, "id": "b4970fe0", "metadata": { "tags": [] @@ -295,7 +295,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 17, "id": "772738cc", "metadata": { "tags": [] @@ -316,7 +316,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 18, "id": "37e67042", "metadata": {}, "outputs": [], @@ -332,7 +332,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 19, "id": "d809a490", "metadata": {}, "outputs": [], @@ -348,7 +348,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 20, "id": "dfc42a8b", "metadata": {}, "outputs": [], @@ -364,7 +364,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 21, "id": "2debf30c", "metadata": {}, "outputs": [], @@ -382,7 +382,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 22, "id": "1e94ea37", "metadata": {}, "outputs": [], @@ -399,7 +399,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 23, "id": "99c96c7f", "metadata": {}, "outputs": [], @@ -416,7 +416,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 24, "id": "b67881ed", "metadata": {}, "outputs": [], @@ -432,7 +432,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 25, "id": "b4515e2b", "metadata": {}, "outputs": [], @@ -449,7 +449,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 26, "id": "8e5b4a14", "metadata": { "tags": [] @@ -468,7 +468,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 27, "id": "2389d6de", "metadata": {}, "outputs": [], @@ -484,7 +484,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 28, "id": "5512edec", "metadata": {}, "outputs": [], @@ -503,7 +503,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 29, "id": "651ab417", "metadata": {}, "outputs": [], @@ -521,7 +521,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 30, "id": "2c0b7d47", "metadata": {}, "outputs": [], @@ -554,7 +554,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 31, "id": "fff80eaa", "metadata": {}, "outputs": [], @@ -570,7 +570,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 32, "id": "4a0eb2a9", "metadata": {}, "outputs": [], @@ -578,7 +578,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 33, "id": "d74ba1b6", "metadata": {}, "outputs": [], @@ -594,7 +594,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 34, "id": "dad3b3bb", "metadata": {}, "outputs": [], @@ -611,7 +611,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 35, "id": "fbd90b0e", "metadata": {}, "outputs": [], @@ -627,7 +627,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 36, "id": "5a101efb", "metadata": {}, "outputs": [], @@ -649,7 +649,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 37, "id": "0a33e2d0", "metadata": {}, "outputs": [], @@ -666,7 +666,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 38, "id": "336a08ca", "metadata": {}, "outputs": [], @@ -683,7 +683,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 39, "id": "991810bc", "metadata": { "tags": [] @@ -702,7 +702,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 40, "id": "f25ebee1", "metadata": {}, "outputs": [], @@ -719,7 +719,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 41, "id": "7ad64412", "metadata": {}, "outputs": [], @@ -739,7 +739,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 42, "id": "b2863701", "metadata": {}, "outputs": [], @@ -747,7 +747,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 43, "id": "cc1afa29", "metadata": {}, "outputs": [], @@ -774,7 +774,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 44, "id": "ad3e6f81", "metadata": {}, "outputs": [], @@ -791,7 +791,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 45, "id": "9ce313ce", "metadata": {}, "outputs": [], @@ -807,7 +807,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 46, "id": "321d9c30", "metadata": {}, "outputs": [], @@ -824,7 +824,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 47, "id": "7eb73d5d", "metadata": {}, "outputs": [], @@ -842,7 +842,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 48, "id": "9529baa8", "metadata": {}, "outputs": [], @@ -858,7 +858,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 49, "id": "dbde77b8", "metadata": {}, "outputs": [], @@ -875,7 +875,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 50, "id": "dbb7d0b3", "metadata": {}, "outputs": [], @@ -891,7 +891,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 51, "id": "49e3fd8e", "metadata": {}, "outputs": [], @@ -909,7 +909,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 52, "id": "9e4f3e51", "metadata": {}, "outputs": [], @@ -925,7 +925,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 53, "id": "c1dcb46d", "metadata": {}, "outputs": [], @@ -945,7 +945,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 54, "id": "aed20c28", "metadata": {}, "outputs": [], @@ -961,7 +961,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 55, "id": "4d9e73b3", "metadata": {}, "outputs": [], @@ -979,7 +979,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 56, "id": "2077dfa9", "metadata": {}, "outputs": [], @@ -995,7 +995,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 57, "id": "b3d40516", "metadata": {}, "outputs": [], @@ -1014,7 +1014,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 58, "id": "8288c28f", "metadata": {}, "outputs": [], @@ -1030,7 +1030,7 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 59, "id": "bbbade35", "metadata": {}, "outputs": [], @@ -1049,7 +1049,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 60, "id": "a4c31795", "metadata": {}, "outputs": [], @@ -1065,7 +1065,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 61, "id": "f3d3619a", "metadata": {}, "outputs": [], @@ -1083,7 +1083,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 62, "id": "f078c8a6", "metadata": {}, "outputs": [], @@ -1100,7 +1100,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 63, "id": "54030d8f", "metadata": {}, "outputs": [], @@ -1132,7 +1132,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 64, "id": "ef158f81", "metadata": {}, "outputs": [], @@ -1150,7 +1150,7 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 65, "id": "d3607b8d", "metadata": {}, "outputs": [], @@ -1170,7 +1170,7 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 66, "id": "692d9cf8", "metadata": {}, "outputs": [], @@ -1199,7 +1199,7 @@ "Lists, dictionaries and tuples are **data structures**.\n", "In this chapter we are starting to see compound data structures, like lists of tuples, or dictionaries that contain tuples as keys and lists as values.\n", "Compound data structures are useful, but they are prone to errors caused when a data structure has the wrong type, size, or structure.\n", - "For example, if a function expects a list if integers and you give it a plain old integer\n", + "For example, if a function expects a list of integers and you give it a plain old integer\n", "(not in a list), it probably won't work.\n", "\n", "To help debug these kinds of errors, I wrote a module called `structshape` that provides a function, also called `structshape`, that takes any kind of data structure as an argument and returns a string that summarizes its structure.\n", @@ -1209,7 +1209,7 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 67, "id": "e9f03e91", "metadata": { "tags": [] @@ -1227,7 +1227,7 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 68, "id": "90ab624a", "metadata": {}, "outputs": [], @@ -1243,7 +1243,7 @@ }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 69, "id": "6794330f", "metadata": {}, "outputs": [], @@ -1259,7 +1259,7 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 70, "id": "54cd185b", "metadata": {}, "outputs": [], @@ -1276,7 +1276,7 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 71, "id": "04028afd", "metadata": {}, "outputs": [], @@ -1292,7 +1292,7 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 72, "id": "b5d45c88", "metadata": {}, "outputs": [], @@ -1308,7 +1308,7 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 73, "id": "15131907", "metadata": {}, "outputs": [], @@ -1359,7 +1359,7 @@ }, { "cell_type": "code", - "execution_count": 73, + "execution_count": 74, "id": "c65d68d2", "metadata": { "tags": [] @@ -1400,7 +1400,7 @@ }, { "cell_type": "code", - "execution_count": 74, + "execution_count": 75, "id": "4416fe4a", "metadata": {}, "outputs": [], @@ -1416,7 +1416,7 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": 76, "id": "e6eda0e4", "metadata": { "tags": [] @@ -1434,7 +1434,7 @@ }, { "cell_type": "code", - "execution_count": 76, + "execution_count": 77, "id": "4fae1acc", "metadata": { "tags": [] @@ -1464,7 +1464,7 @@ }, { "cell_type": "code", - "execution_count": 77, + "execution_count": 78, "id": "855c7ed2", "metadata": {}, "outputs": [], @@ -1480,7 +1480,7 @@ }, { "cell_type": "code", - "execution_count": 78, + "execution_count": 79, "id": "3c921f68", "metadata": {}, "outputs": [], @@ -1497,7 +1497,7 @@ }, { "cell_type": "code", - "execution_count": 79, + "execution_count": 80, "id": "b029b0da", "metadata": {}, "outputs": [], @@ -1534,7 +1534,7 @@ }, { "cell_type": "code", - "execution_count": 80, + "execution_count": 81, "id": "1cc07036", "metadata": { "tags": [] @@ -1544,7 +1544,7 @@ }, { "cell_type": "code", - "execution_count": 81, + "execution_count": 82, "id": "96560a0e", "metadata": {}, "outputs": [], @@ -1552,7 +1552,7 @@ }, { "cell_type": "code", - "execution_count": 82, + "execution_count": 83, "id": "c026c6d1", "metadata": { "tags": [] @@ -1562,7 +1562,7 @@ }, { "cell_type": "code", - "execution_count": 83, + "execution_count": 84, "id": "5814999d", "metadata": { "tags": [] @@ -1582,7 +1582,7 @@ }, { "cell_type": "code", - "execution_count": 84, + "execution_count": 85, "id": "9464d140", "metadata": { "tags": [] @@ -1614,7 +1614,7 @@ }, { "cell_type": "code", - "execution_count": 85, + "execution_count": 86, "id": "4309d0b5", "metadata": { "tags": [] @@ -1624,7 +1624,7 @@ }, { "cell_type": "code", - "execution_count": 86, + "execution_count": 87, "id": "52228828", "metadata": {}, "outputs": [], @@ -1642,7 +1642,7 @@ }, { "cell_type": "code", - "execution_count": 87, + "execution_count": 88, "id": "3bf2aa0d", "metadata": { "tags": [] @@ -1662,7 +1662,7 @@ }, { "cell_type": "code", - "execution_count": 88, + "execution_count": 89, "id": "e4fbf5d9", "metadata": { "tags": [] @@ -1672,7 +1672,7 @@ }, { "cell_type": "code", - "execution_count": 89, + "execution_count": 90, "id": "817ec689", "metadata": { "tags": [] @@ -1724,7 +1724,7 @@ }, { "cell_type": "code", - "execution_count": 90, + "execution_count": 91, "id": "941719c1", "metadata": { "tags": [] @@ -1734,7 +1734,7 @@ }, { "cell_type": "code", - "execution_count": 91, + "execution_count": 92, "id": "d2ec641b", "metadata": { "tags": [] @@ -1754,7 +1754,7 @@ }, { "cell_type": "code", - "execution_count": 92, + "execution_count": 93, "id": "7ae29f73", "metadata": { "tags": [] @@ -1764,7 +1764,7 @@ }, { "cell_type": "code", - "execution_count": 93, + "execution_count": 94, "id": "013819a5", "metadata": {}, "outputs": [], @@ -1783,7 +1783,7 @@ }, { "cell_type": "code", - "execution_count": 94, + "execution_count": 95, "id": "fbf9ede3", "metadata": { "tags": [] @@ -1803,7 +1803,7 @@ }, { "cell_type": "code", - "execution_count": 95, + "execution_count": 96, "id": "55435050", "metadata": { "tags": [] @@ -1823,7 +1823,7 @@ }, { "cell_type": "code", - "execution_count": 96, + "execution_count": 97, "id": "6a9320c2", "metadata": { "tags": [] @@ -1855,7 +1855,7 @@ }, { "cell_type": "code", - "execution_count": 97, + "execution_count": 98, "id": "3d5a75f8", "metadata": { "tags": [] @@ -1865,7 +1865,7 @@ }, { "cell_type": "code", - "execution_count": 98, + "execution_count": 99, "id": "a9816dde", "metadata": {}, "outputs": [], @@ -1873,7 +1873,7 @@ }, { "cell_type": "code", - "execution_count": 99, + "execution_count": 100, "id": "753a23c1", "metadata": { "tags": [] @@ -1899,7 +1899,7 @@ }, { "cell_type": "code", - "execution_count": 100, + "execution_count": 101, "id": "57649075", "metadata": {}, "outputs": [], @@ -1959,7 +1959,7 @@ }, { "cell_type": "code", - "execution_count": 101, + "execution_count": 102, "id": "c19bf833", "metadata": {}, "outputs": [], @@ -1967,7 +1967,7 @@ }, { "cell_type": "code", - "execution_count": 102, + "execution_count": 103, "id": "2d9764d6", "metadata": {}, "outputs": [], @@ -1975,7 +1975,7 @@ }, { "cell_type": "code", - "execution_count": 103, + "execution_count": 104, "id": "5e4f5d8e", "metadata": {}, "outputs": [], @@ -1983,7 +1983,7 @@ }, { "cell_type": "code", - "execution_count": 104, + "execution_count": 105, "id": "27d311dd", "metadata": {}, "outputs": [], @@ -1991,19 +1991,27 @@ }, { "cell_type": "code", - "execution_count": 105, + "execution_count": 106, "id": "68c27c7e", "metadata": {}, "outputs": [], "source": [] }, { - "cell_type": "code", - "execution_count": null, - "id": "a34c2014", - "metadata": {}, - "outputs": [], - "source": [] + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { @@ -2023,7 +2031,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.14" + "version": "3.10.11" } }, "nbformat": 4, diff --git a/blank/chap12.ipynb b/blank/chap12.ipynb index d9ac117a..220b664c 100644 --- a/blank/chap12.ipynb +++ b/blank/chap12.ipynb @@ -27,7 +27,7 @@ "source": [ "# Text Analysis and Generation\n", "\n", - "At this point we have covered Python's core data structures -- lists, dictionaries, and tuples -- and and some algorithms that use them.\n", + "At this point we have covered Python's core data structures -- lists, dictionaries, and tuples -- and some algorithms that use them.\n", "In this chapter, we'll use them to explore text analysis and Markov generation:\n", "\n", "* Text analysis is a way to describe the statistical relationships between the words in a document, like the probability that one word is followed by another, and\n", @@ -1771,6 +1771,22 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { diff --git a/blank/chap13.ipynb b/blank/chap13.ipynb index e346fce9..69616a9f 100644 --- a/blank/chap13.ipynb +++ b/blank/chap13.ipynb @@ -283,7 +283,7 @@ "id": "f652aaac", "metadata": {}, "source": [ - "To write this data to a file, you can use the `write` method, which we saw in [Chapter 8](section_writing_files).\n", + "To write this data to a file, you can use the `write` method, which we saw in Chapter 8.\n", "The argument of `write` has to be a string, so if we want to put other values in a file, we have to convert them to strings.\n", "The easiest way to do that is with the built-in function `str`.\n", "\n", @@ -1634,6 +1634,22 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { diff --git a/blank/chap14.ipynb b/blank/chap14.ipynb index c9b0f0f4..38aaffc3 100644 --- a/blank/chap14.ipynb +++ b/blank/chap14.ipynb @@ -1415,6 +1415,22 @@ "id": "d6f1cc2f", "metadata": {}, "source": [] + }, + { + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { diff --git a/blank/chap15.ipynb b/blank/chap15.ipynb index dc133c2d..2ffde334 100644 --- a/blank/chap15.ipynb +++ b/blank/chap15.ipynb @@ -881,6 +881,22 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { diff --git a/blank/chap16.ipynb b/blank/chap16.ipynb index 987c2ccd..4309183a 100644 --- a/blank/chap16.ipynb +++ b/blank/chap16.ipynb @@ -1508,6 +1508,22 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { diff --git a/blank/chap17.ipynb b/blank/chap17.ipynb index eb142740..bc6b43ee 100644 --- a/blank/chap17.ipynb +++ b/blank/chap17.ipynb @@ -2102,6 +2102,22 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { diff --git a/blank/chap18.ipynb b/blank/chap18.ipynb index 8487e414..6a069c18 100644 --- a/blank/chap18.ipynb +++ b/blank/chap18.ipynb @@ -1513,7 +1513,7 @@ "metadata": {}, "source": [ "`run_unittest` does not take `TestExample` as an argument -- instead, it searches for classes that inherit from `TestCase`.\n", - "Then is searches for methods that begin with `test` and runs them.\n", + "Then it searches for methods that begin with `test` and runs them.\n", "This process is called **test discovery**.\n", "\n", "Here's what happens when we call `run_unittest`." @@ -2045,6 +2045,22 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { diff --git a/blank/chap19.ipynb b/blank/chap19.ipynb index 190c3e62..4d86fb8f 100644 --- a/blank/chap19.ipynb +++ b/blank/chap19.ipynb @@ -146,6 +146,22 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "markdown", + "id": "a7f4edf8", + "metadata": { + "tags": [] + }, + "source": [ + "[Think Python: 3rd Edition](https://allendowney.github.io/ThinkPython/index.html)\n", + "\n", + "Copyright 2024 [Allen B. Downey](https://allendowney.com)\n", + "\n", + "Code license: [MIT License](https://mit-license.org/)\n", + "\n", + "Text license: [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-nc-sa/4.0/)" + ] } ], "metadata": { diff --git a/chapters/chap00.ipynb b/chapters/chap00.ipynb index 55b62c27..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", @@ -171,9 +171,9 @@ "\n", "If you are teaching with this book, here are some resources you might find useful.\n", "\n", - "* You can find notebooks with solutions to the exercises from , along with links to the additional resources below.\n", + "* You can find notebooks with solutions to the exercises at , along with links to the additional resources below.\n", "\n", - "* Quizzes for each chapter, and a summative quiz for the whole book, are available from [COMING SOON]\n", + "* Quizzes for each chapter, and a summative quiz for the whole book, are available on request.\n", "\n", "* *Teaching and Learning with Jupyter* is an online book with suggestions for using Jupyter effectively in the classroom. You can read the book at \n", "\n", diff --git a/chapters/chap03.ipynb b/chapters/chap03.ipynb index 64e293f1..5f2cb1d3 100644 --- a/chapters/chap03.ipynb +++ b/chapters/chap03.ipynb @@ -580,13 +580,13 @@ "frame2 = make_frame(d2, name='cat_twice', dy=-0.3, \n", " offsetx=0.03, loc='left')\n", "\n", - "d3 = dict(s = line1+line2)\n", + "d3 = dict(string=line1+line2)\n", "frame3 = make_frame(d3, name='print_twice', \n", - " offsetx=-0.28, offsety=-0.3, loc='left')\n", + " offsetx=0.04, offsety=-0.3, loc='left')\n", "\n", "d4 = {\"?\": line1+line2}\n", "frame4 = make_frame(d4, name='print', \n", - " offsetx=-0.28, offsety=0, loc='left')\n", + " offsetx=-0.22, offsety=0, loc='left')\n", "\n", "stack = Stack([frame1, frame2, frame3, frame4], dy=-0.8)" ] @@ -603,10 +603,13 @@ "from diagram import diagram, adjust\n", "\n", "\n", - "width, height, x, y = [3.8, 2.91, 1.15, 2.66]\n", + "width, height, x, y = [3.77, 2.9, 1.1, 2.65]\n", "ax = diagram(width, height)\n", "bbox = stack.draw(ax, x, y)\n", - "#adjust(x, y, bbox)" + "# adjust(x, y, bbox)\n", + "\n", + "import matplotlib.pyplot as plt\n", + "plt.savefig('chap03_stack_diagram.png', dpi=300)" ] }, { diff --git a/chapters/chap06.ipynb b/chapters/chap06.ipynb index 1d306833..a8d03c32 100644 --- a/chapters/chap06.ipynb +++ b/chapters/chap06.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": 87, + "execution_count": 5, "id": "56b1c184", "metadata": { "tags": [] @@ -66,7 +66,7 @@ }, { "cell_type": "code", - "execution_count": 88, + "execution_count": 6, "id": "e0e1dd91", "metadata": {}, "outputs": [], @@ -86,7 +86,7 @@ }, { "cell_type": "code", - "execution_count": 89, + "execution_count": 7, "id": "5aaf62d2", "metadata": {}, "outputs": [], @@ -104,7 +104,7 @@ }, { "cell_type": "code", - "execution_count": 90, + "execution_count": 8, "id": "741f7386", "metadata": {}, "outputs": [], @@ -122,7 +122,7 @@ }, { "cell_type": "code", - "execution_count": 91, + "execution_count": 9, "id": "e56d39c4", "metadata": {}, "outputs": [], @@ -140,7 +140,7 @@ }, { "cell_type": "code", - "execution_count": 92, + "execution_count": 10, "id": "50a9a9be", "metadata": {}, "outputs": [], @@ -164,7 +164,7 @@ }, { "cell_type": "code", - "execution_count": 93, + "execution_count": 11, "id": "d70fd9b5", "metadata": {}, "outputs": [], @@ -182,7 +182,7 @@ }, { "cell_type": "code", - "execution_count": 94, + "execution_count": 12, "id": "ef20ba8c", "metadata": {}, "outputs": [], @@ -200,7 +200,7 @@ }, { "cell_type": "code", - "execution_count": 95, + "execution_count": 13, "id": "0a4670f4", "metadata": {}, "outputs": [], @@ -218,7 +218,7 @@ }, { "cell_type": "code", - "execution_count": 96, + "execution_count": 14, "id": "6e6460b9", "metadata": {}, "outputs": [], @@ -236,7 +236,7 @@ }, { "cell_type": "code", - "execution_count": 97, + "execution_count": 15, "id": "77613df9", "metadata": { "tags": [] @@ -269,7 +269,7 @@ }, { "cell_type": "code", - "execution_count": 98, + "execution_count": 16, "id": "89c083f8", "metadata": {}, "outputs": [], @@ -288,7 +288,7 @@ }, { "cell_type": "code", - "execution_count": 99, + "execution_count": 17, "id": "737b67ca", "metadata": {}, "outputs": [], @@ -307,7 +307,7 @@ }, { "cell_type": "code", - "execution_count": 100, + "execution_count": 18, "id": "9b4fa14f", "metadata": {}, "outputs": [], @@ -325,7 +325,7 @@ }, { "cell_type": "code", - "execution_count": 101, + "execution_count": 19, "id": "50f96bcb", "metadata": {}, "outputs": [], @@ -344,7 +344,7 @@ }, { "cell_type": "code", - "execution_count": 102, + "execution_count": 20, "id": "6712f2df", "metadata": {}, "outputs": [], @@ -364,7 +364,7 @@ }, { "cell_type": "code", - "execution_count": 103, + "execution_count": 21, "id": "0ec1afd3", "metadata": {}, "outputs": [], @@ -386,7 +386,7 @@ }, { "cell_type": "code", - "execution_count": 104, + "execution_count": 22, "id": "c82334b6", "metadata": {}, "outputs": [], @@ -404,7 +404,7 @@ }, { "cell_type": "code", - "execution_count": 105, + "execution_count": 23, "id": "595ec598", "metadata": {}, "outputs": [], @@ -432,7 +432,7 @@ }, { "cell_type": "code", - "execution_count": 106, + "execution_count": 24, "id": "236c59e6", "metadata": {}, "outputs": [], @@ -459,7 +459,7 @@ }, { "cell_type": "code", - "execution_count": 107, + "execution_count": 25, "id": "2f60639c", "metadata": {}, "outputs": [], @@ -481,7 +481,7 @@ }, { "cell_type": "code", - "execution_count": 108, + "execution_count": 26, "id": "c9dae6c8", "metadata": {}, "outputs": [], @@ -501,7 +501,7 @@ }, { "cell_type": "code", - "execution_count": 109, + "execution_count": 27, "id": "c8c4edee", "metadata": {}, "outputs": [], @@ -555,7 +555,7 @@ }, { "cell_type": "code", - "execution_count": 110, + "execution_count": 28, "id": "bbcab1ed", "metadata": {}, "outputs": [], @@ -577,7 +577,7 @@ }, { "cell_type": "code", - "execution_count": 111, + "execution_count": 29, "id": "923d96db", "metadata": {}, "outputs": [], @@ -601,7 +601,7 @@ }, { "cell_type": "code", - "execution_count": 112, + "execution_count": 30, "id": "9374cfe3", "metadata": {}, "outputs": [], @@ -627,7 +627,7 @@ }, { "cell_type": "code", - "execution_count": 113, + "execution_count": 31, "id": "405af839", "metadata": {}, "outputs": [], @@ -645,7 +645,7 @@ }, { "cell_type": "code", - "execution_count": 114, + "execution_count": 32, "id": "e52b3b04", "metadata": {}, "outputs": [], @@ -668,7 +668,7 @@ }, { "cell_type": "code", - "execution_count": 115, + "execution_count": 33, "id": "38eebbf3", "metadata": {}, "outputs": [], @@ -686,7 +686,7 @@ }, { "cell_type": "code", - "execution_count": 116, + "execution_count": 34, "id": "b4536ea0", "metadata": {}, "outputs": [], @@ -709,7 +709,7 @@ }, { "cell_type": "code", - "execution_count": 117, + "execution_count": 35, "id": "325efb93", "metadata": {}, "outputs": [], @@ -729,7 +729,7 @@ }, { "cell_type": "code", - "execution_count": 118, + "execution_count": 36, "id": "3cd982ce", "metadata": {}, "outputs": [], @@ -753,7 +753,7 @@ }, { "cell_type": "code", - "execution_count": 119, + "execution_count": 37, "id": "c734f5b2", "metadata": {}, "outputs": [], @@ -771,7 +771,7 @@ }, { "cell_type": "code", - "execution_count": 120, + "execution_count": 38, "id": "094a242f", "metadata": {}, "outputs": [], @@ -813,7 +813,7 @@ }, { "cell_type": "code", - "execution_count": 121, + "execution_count": 39, "id": "64207948", "metadata": {}, "outputs": [], @@ -835,7 +835,7 @@ }, { "cell_type": "code", - "execution_count": 122, + "execution_count": 40, "id": "c367cdae", "metadata": {}, "outputs": [], @@ -845,7 +845,7 @@ }, { "cell_type": "code", - "execution_count": 123, + "execution_count": 41, "id": "837f4f95", "metadata": {}, "outputs": [], @@ -864,7 +864,7 @@ }, { "cell_type": "code", - "execution_count": 124, + "execution_count": 42, "id": "e411354f", "metadata": {}, "outputs": [], @@ -883,7 +883,7 @@ }, { "cell_type": "code", - "execution_count": 125, + "execution_count": 43, "id": "925e7d4f", "metadata": {}, "outputs": [], @@ -902,7 +902,7 @@ }, { "cell_type": "code", - "execution_count": 126, + "execution_count": 44, "id": "62178e75", "metadata": {}, "outputs": [], @@ -949,7 +949,7 @@ }, { "cell_type": "code", - "execution_count": 127, + "execution_count": 45, "id": "23e37c79", "metadata": {}, "outputs": [], @@ -968,7 +968,7 @@ }, { "cell_type": "code", - "execution_count": 128, + "execution_count": 46, "id": "5ea57d9f", "metadata": {}, "outputs": [], @@ -991,7 +991,7 @@ }, { "cell_type": "code", - "execution_count": 129, + "execution_count": 47, "id": "b66e670b", "metadata": {}, "outputs": [], @@ -1039,7 +1039,7 @@ }, { "cell_type": "code", - "execution_count": 130, + "execution_count": 48, "id": "455f0457", "metadata": { "tags": [] @@ -1063,7 +1063,7 @@ " loc='left', dx=1.2)\n", " frames.append(frame)\n", " \n", - "binding1 = make_binding('n', n)\n", + "binding1 = make_binding('n', 0)\n", "frame = Frame([binding1], name='factorial', value=1, \n", " shim=1.2, loc='left', dx=1.4)\n", "frames.append(frame)\n", @@ -1073,7 +1073,7 @@ }, { "cell_type": "code", - "execution_count": 131, + "execution_count": 49, "id": "a75ccd9b", "metadata": { "tags": [] @@ -1142,7 +1142,7 @@ }, { "cell_type": "code", - "execution_count": 132, + "execution_count": 50, "id": "cad75752", "metadata": {}, "outputs": [], @@ -1180,7 +1180,7 @@ }, { "cell_type": "code", - "execution_count": 133, + "execution_count": 51, "id": "5e4b5f1d", "metadata": { "tags": [] @@ -1197,8 +1197,7 @@ "id": "0bec7ba4", "metadata": {}, "source": [ - "It looks like an infinite recursion. How can that be? The function has a\n", - "base case -- when `n == 0`.\n", + "It looks like an infinite recursion. How can that be? The function has base cases when `n == 1` or `n == 0`.\n", "But if `n` is not an integer, we can *miss* the base case and recurse forever.\n", "\n", "In this example, the initial value of `n` is `1.5`.\n", @@ -1212,7 +1211,7 @@ }, { "cell_type": "code", - "execution_count": 134, + "execution_count": 52, "id": "3f607dff", "metadata": {}, "outputs": [], @@ -1222,7 +1221,7 @@ }, { "cell_type": "code", - "execution_count": 135, + "execution_count": 53, "id": "ab638bfe", "metadata": {}, "outputs": [], @@ -1240,7 +1239,7 @@ }, { "cell_type": "code", - "execution_count": 136, + "execution_count": 54, "id": "73aafac0", "metadata": {}, "outputs": [], @@ -1270,7 +1269,7 @@ }, { "cell_type": "code", - "execution_count": 137, + "execution_count": 55, "id": "be881cb7", "metadata": {}, "outputs": [], @@ -1289,7 +1288,7 @@ }, { "cell_type": "code", - "execution_count": 138, + "execution_count": 56, "id": "fa83014f", "metadata": {}, "outputs": [], @@ -1338,7 +1337,7 @@ }, { "cell_type": "code", - "execution_count": 139, + "execution_count": 57, "id": "1d50479e", "metadata": {}, "outputs": [], @@ -1367,7 +1366,7 @@ }, { "cell_type": "code", - "execution_count": 140, + "execution_count": 58, "id": "798db5c4", "metadata": {}, "outputs": [], @@ -1424,7 +1423,7 @@ }, { "cell_type": "code", - "execution_count": 142, + "execution_count": 59, "id": "e0f15ca4", "metadata": { "tags": [] @@ -1449,7 +1448,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 60, "id": "90b4979f", "metadata": {}, "outputs": [], @@ -1471,7 +1470,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 61, "id": "9217f038", "metadata": {}, "outputs": [], @@ -1495,7 +1494,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 62, "id": "3168489b", "metadata": {}, "outputs": [], @@ -1534,7 +1533,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 63, "id": "62267fa3", "metadata": {}, "outputs": [], @@ -1544,7 +1543,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 64, "id": "5f8fa829", "metadata": {}, "outputs": [], @@ -1554,7 +1553,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 65, "id": "3d129b03", "metadata": {}, "outputs": [], @@ -1564,7 +1563,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 66, "id": "030179b6", "metadata": {}, "outputs": [], @@ -1574,7 +1573,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 67, "id": "d737b468", "metadata": {}, "outputs": [], @@ -1584,7 +1583,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 68, "id": "77a74879", "metadata": {}, "outputs": [], @@ -1594,7 +1593,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 69, "id": "0521d267", "metadata": {}, "outputs": [], @@ -1604,7 +1603,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 70, "id": "468a31e9", "metadata": {}, "outputs": [], @@ -1614,7 +1613,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 71, "id": "abbe3ebf", "metadata": {}, "outputs": [], @@ -1624,7 +1623,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 72, "id": "651295e4", "metadata": {}, "outputs": [], @@ -1645,7 +1644,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 73, "id": "0a4ee482", "metadata": {}, "outputs": [], @@ -1665,7 +1664,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 74, "id": "956ed6d7", "metadata": { "tags": [] @@ -1677,7 +1676,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 75, "id": "a994eaa6", "metadata": { "tags": [] @@ -1689,7 +1688,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 76, "id": "4318028d", "metadata": { "tags": [] @@ -1701,7 +1700,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 77, "id": "05208c8b", "metadata": { "tags": [] @@ -1734,7 +1733,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 78, "id": "7eb85c5c", "metadata": {}, "outputs": [], @@ -1754,7 +1753,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 79, "id": "687a3e5a", "metadata": { "tags": [] @@ -1766,7 +1765,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 80, "id": "c49e9749", "metadata": { "tags": [] @@ -1778,7 +1777,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 81, "id": "8497dec4", "metadata": { "tags": [] @@ -1800,7 +1799,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 82, "id": "76be4d15", "metadata": { "tags": [] @@ -1839,7 +1838,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 83, "id": "0bcba5fe", "metadata": {}, "outputs": [], @@ -1859,7 +1858,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 84, "id": "4b6656e6", "metadata": { "tags": [] @@ -1871,7 +1870,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 85, "id": "36d9e92a", "metadata": { "tags": [] @@ -1883,7 +1882,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 86, "id": "1d944b42", "metadata": { "tags": [] @@ -1895,7 +1894,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 87, "id": "63ec57c9", "metadata": { "tags": [] @@ -1925,7 +1924,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 88, "id": "4e067bfb", "metadata": {}, "outputs": [], @@ -1945,7 +1944,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 89, "id": "2a7c1c21", "metadata": { "tags": [] @@ -1957,7 +1956,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 90, "id": "5df00229", "metadata": { "tags": [] diff --git a/chapters/chap07.ipynb b/chapters/chap07.ipynb index 0b231c6f..9d9c634b 100644 --- a/chapters/chap07.ipynb +++ b/chapters/chap07.ipynb @@ -815,7 +815,7 @@ "## Search\n", "\n", "Based on this simpler version of `has_e`, let's write a more general function called `uses_any` that takes a second parameter that is a string of letters.\n", - "If returns `True` if the word uses any of the letters and `False` otherwise." + "It returns `True` if the word uses any of the letters and `False` otherwise." ] }, { @@ -1076,7 +1076,7 @@ " A variable used to count something, usually initialized to zero and then incremented.\n", "\n", "**linear search:**\n", - "A computational pattern that searches through a sequence of elements and stops what it finds what it is looking for.\n", + "A computational pattern that searches through a sequence of elements and stops when it finds what it is looking for.\n", "\n", "**pass:**\n", "If a test runs and the result is as expected, the test passes.\n", @@ -1472,6 +1472,7 @@ "source": [ "available = 'ACDLORT'\n", "required = 'R'\n", + "\n", "total = 0\n", "\n", "file_object = open('words.txt')\n", @@ -1612,6 +1613,24 @@ { "cell_type": "code", "execution_count": 71, + "id": "a3ea747d", + "metadata": {}, + "outputs": [], + "source": [ + "# Here's what I got from ChatGPT 4o December 26, 2024\n", + "# It's correct, but it makes multiple calls to uses_any \n", + "\n", + "def uses_all(s1, s2):\n", + " \"\"\"Checks if all characters in s2 are in s1, allowing repeats.\"\"\"\n", + " for char in s2:\n", + " if not uses_any(s1, char):\n", + " return False\n", + " return True\n" + ] + }, + { + "cell_type": "code", + "execution_count": 72, "id": "6980de57", "metadata": {}, "outputs": [], diff --git a/chapters/chap08.ipynb b/chapters/chap08.ipynb index 1323762c..01083129 100644 --- a/chapters/chap08.ipynb +++ b/chapters/chap08.ipynb @@ -862,7 +862,7 @@ "id": "34c93df3", "metadata": {}, "source": [ - "The `endswidth` method checks whether a string ends with a given sequence of characters." + "The `endswith` method checks whether a string ends with a given sequence of characters." ] }, { diff --git a/chapters/chap09.ipynb b/chapters/chap09.ipynb index 93f8fd6f..755c656f 100644 --- a/chapters/chap09.ipynb +++ b/chapters/chap09.ipynb @@ -895,7 +895,7 @@ "id": "f90bd9ea", "metadata": {}, "source": [ - "The result it a list.\n", + "The result is a list.\n", "To convert the list to a string, we can use `join`." ] }, @@ -1746,7 +1746,7 @@ "id": "8fc79a2f", "metadata": {}, "source": [ - "Of if you want them in a string, you can use the `join` method." + "Or if you want them in a string, you can use the `join` method." ] }, { diff --git a/chapters/chap10.ipynb b/chapters/chap10.ipynb index 51dac268..742da868 100644 --- a/chapters/chap10.ipynb +++ b/chapters/chap10.ipynb @@ -477,7 +477,7 @@ "metadata": {}, "source": [ "The following function loops through the words in the list.\n", - "For each one, it reverses the letters and then checks whether the reversed word in the word list." + "For each one, it reverses the letters and then checks whether the reversed word is in the word list." ] }, { @@ -505,6 +505,17 @@ "If it doesn't find what it's looking for -- which happens most of the time -- it has to search all the way to the end." ] }, + { + "cell_type": "markdown", + "id": "fac41347", + "metadata": { + "tags": [] + }, + "source": [ + "To measure how long a function takes, we can use `%time` which is one of Jupyter's \"built-in magic commands\".\n", + "These commands are not part of the Python language, so they might not work in other development environments." + ] + }, { "cell_type": "code", "execution_count": 58, @@ -590,18 +601,6 @@ "This function takes less than one hundredth of a second, so it's about 10,000 times faster than the previous version." ] }, - { - "cell_type": "code", - "execution_count": 62, - "id": "82b36568", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "%time much_faster()" - ] - }, { "cell_type": "markdown", "id": "4cd91c99", @@ -613,14 +612,14 @@ }, { "cell_type": "code", - "execution_count": 63, - "id": "aa079ed3", - "metadata": {}, + "execution_count": 62, + "id": "82b36568", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "d = {'a': 1, 'b': 2}\n", - "d['a'] = 3\n", - "d" + "%time much_faster()" ] }, { @@ -1213,17 +1212,6 @@ "In the notebook for this chapter, you'll see where these measurements come from." ] }, - { - "cell_type": "markdown", - "id": "c6f39f84", - "metadata": { - "tags": [] - }, - "source": [ - "To measure how long a function takes, we can use `%time` which is one of Jupyter's \"built-in magic commands\".\n", - "These commands are not part of the Python language, so they might not work in other development environments." - ] - }, { "cell_type": "code", "execution_count": 50, @@ -1376,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", @@ -1571,7 +1559,7 @@ "source": [ "### Exercise\n", "\n", - "Write function called `find_repeats` that takes a dictionary that maps from each key to a counter, like the result from `value_counts`.\n", + "Write a function called `find_repeats` that takes a dictionary that maps from each key to a counter, like the result from `value_counts`.\n", "It should loop through the dictionary and return a list of keys that have counts greater than `1`.\n", "You can use the following outline to get started." ] @@ -1809,10 +1797,16 @@ "cell_type": "code", "execution_count": 70, "id": "e04a5c73", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "# Solution goes here" + "for word in word_list:\n", + " if len(word) >= 8 and is_interlocking(word):\n", + " first = word[0::2]\n", + " second = word[1::2]\n", + " print(word, first, second)" ] }, { diff --git a/chapters/chap12.ipynb b/chapters/chap12.ipynb index f3f7b194..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": [], @@ -520,12 +520,12 @@ "\n", "* `key=second_element` means the items will be sorted according to the frequencies of the words.\n", "\n", - "* `reverse=True` means they items will be sorted in reverse order, with the most frequent words first." + "* `reverse=True` means the items will be sorted in reverse order, with the most frequent words first." ] }, { "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": [], @@ -730,12 +730,12 @@ "id": "22becbab", "metadata": {}, "source": [ - "The we'll store the words as keys in a dictionary so we can use the `in` operator to check quickly whether a word is valid." + "Then we'll store the words as keys in a dictionary so we can use the `in` operator to check quickly whether a word is valid." ] }, { "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": [], @@ -1827,7 +1827,7 @@ "metadata": {}, "source": [ "Dictionaries provide a method called `setdefault` that we can use to do the same thing more concisely.\n", - "Ask a virtual assistant how it works, or copy `add_word` into a virtual assistant and ask \"Can you rewrite this using `setdefault`?\"\n", + "Ask a virtual assistant how it works, or copy `add_bigram` into a virtual assistant and ask \"Can you rewrite this using `setdefault`?\"\n", "\n", "In this chapter we implemented Markov chain text analysis and generation.\n", "If you are curious, you can ask a virtual assistant for more information on the topic.\n", @@ -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 b8269895..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", @@ -1587,9 +1599,7 @@ { "cell_type": "markdown", "id": "85844afb", - "metadata": { - "tags": [] - }, + "metadata": {}, "source": [ "Here's an outline of the function to get you started." ] @@ -1601,7 +1611,14 @@ "metadata": {}, "outputs": [], "source": [ - "# Solution goes here" + "def replace_all(old, new, source_path, dest_path):\n", + " # read the contents of the source file\n", + " reader = open(source_path)\n", + "\n", + " # replace the old string with the new\n", + " \n", + " # write the result into the destination file\n", + " " ] }, { diff --git a/chapters/chap14.ipynb b/chapters/chap14.ipynb index b71f7068..f0f9998a 100644 --- a/chapters/chap14.ipynb +++ b/chapters/chap14.ipynb @@ -359,7 +359,7 @@ "metadata": {}, "source": [ "It might be surprising that the parameters have the same names as the attributes, but that's a common way to write a function like this.\n", - "Here's how we use `make_time` to create a `Time` object.`" + "Here's how we use `make_time` to create a `Time` object." ] }, { @@ -907,7 +907,7 @@ " \n", " carry, time.second = divmod(time.second, 60)\n", " carry, time.minute = divmod(time.minute + carry, 60)\n", - " carry, time.hour = divmod(time.hour + carry, 60)" + " carry, time.hour = divmod(time.hour + carry, 24)" ] }, { @@ -981,7 +981,7 @@ "metadata": {}, "source": [ "The result is the number of seconds since the beginning of the day.\n", - "For example, `01:01:01` is `1` hour, `1` minute and `1` second from the beginning of the day, with is the sum of `3600` seconds, `60` seconds, and `1` second." + "For example, `01:01:01` is `1` hour, `1` minute and `1` second from the beginning of the day, which is the sum of `3600` seconds, `60` seconds, and `1` second." ] }, { @@ -1307,14 +1307,6 @@ "Also, in this chapter we saw one example of a format specifier. For more information, ask \"What format specifiers can be used in a Python f-string?\"" ] }, - { - "cell_type": "markdown", - "id": "c85eab62", - "metadata": {}, - "source": [ - "## Exercises\n" - ] - }, { "cell_type": "markdown", "id": "bcdab7d6", diff --git a/chapters/chap15.ipynb b/chapters/chap15.ipynb index 91d12714..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()" ] }, { @@ -604,7 +604,7 @@ "id": "e01e9673", "metadata": {}, "source": [ - "## The __init__ method\n", + "## The init method\n", "\n", "The most special of the special methods is `__init__`, so-called because it initializes the attributes of a new object.\n", "An `__init__` method for the `Time` class might look like this:" @@ -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": [], @@ -983,16 +983,16 @@ "\n", "2. Write an `__init__` method that takes `year`, `month`, and `day` as parameters and assigns the parameters to attributes. Create an object that represents June 22, 1933.\n", "\n", - "2. Write `__str__` method that uses an f-string to format the attributes and returns the result. If you test it with the `Date` you created, the result should be `1933-06-22`.\n", + "3. Write `__str__` method that uses an f-string to format the attributes and returns the result. If you test it with the `Date` you created, the result should be `1933-06-22`.\n", "\n", - "3. Write a method called `is_after` that takes two `Date` objects and returns `True` if the first comes after the second. Create a second object that represents September 17, 1933, and check whether it comes after the first object.\n", + "4. Write a method called `is_after` that takes two `Date` objects and returns `True` if the first comes after the second. Create a second object that represents September 17, 1933, and check whether it comes after the first object.\n", "\n", "Hint: You might find it useful write a method called `to_tuple` that returns a tuple that contains the attributes of a `Date` object in year-month-day order." ] }, { "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 01fd85ba..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:" ] @@ -1279,9 +1279,7 @@ { "cell_type": "markdown", "id": "2e488e0f", - "metadata": { - "tags": [] - }, + "metadata": {}, "source": [ "You can use the following outline to get started." ] @@ -1290,9 +1288,7 @@ "cell_type": "code", "execution_count": 49, "id": "92c07380", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "%%add_method_to Line\n", @@ -1310,22 +1306,13 @@ }, "outputs": [], "source": [ - "%%add_method_to Line\n", - "\n", - "def __eq__(self, other):\n", - " if (self.p1 == other.p1) and (self.p2 == other.p2):\n", - " return True\n", - " if (self.p1 == other.p2) and (self.p2 == other.p1):\n", - " return True\n", - " return False" + "# Solution goes here" ] }, { "cell_type": "markdown", "id": "3a44e45a", - "metadata": { - "tags": [] - }, + "metadata": {}, "source": [ "You can use these examples to test your code." ] @@ -1334,9 +1321,7 @@ "cell_type": "code", "execution_count": 51, "id": "aa086dd1", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "start1 = Point(0, 0)\n", @@ -1347,9 +1332,7 @@ { "cell_type": "markdown", "id": "e825f049", - "metadata": { - "tags": [] - }, + "metadata": {}, "source": [ "This example should be `True` because the `Line` objects refer to `Point` objects that are equivalent, in the same order." ] @@ -1358,9 +1341,7 @@ "cell_type": "code", "execution_count": 52, "id": "857cba26", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "line_a = Line(start1, end)\n", @@ -1382,9 +1363,7 @@ "cell_type": "code", "execution_count": 53, "id": "b45def0a", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "line_c = Line(end, start1)\n", @@ -1394,9 +1373,7 @@ { "cell_type": "markdown", "id": "8c9c787b", - "metadata": { - "tags": [] - }, + "metadata": {}, "source": [ "Equivalence should always be transitive -- that is, if `line_a` and `line_b` are equivalent, and `line_a` and `line_c` are equivalent, then `line_b` and `line_c` should also be equivalent." ] @@ -1405,9 +1382,7 @@ "cell_type": "code", "execution_count": 54, "id": "9784300c", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "line_b == line_c # should be True" @@ -1416,9 +1391,7 @@ { "cell_type": "markdown", "id": "d4f385fa", - "metadata": { - "tags": [] - }, + "metadata": {}, "source": [ "This example should be `False` because the `Line` objects refer to `Point` objects that are not equivalent." ] @@ -1427,9 +1400,7 @@ "cell_type": "code", "execution_count": 55, "id": "5435c8e4", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "line_d = Line(start1, start2)\n", @@ -1449,9 +1420,7 @@ { "cell_type": "markdown", "id": "b8c52d19", - "metadata": { - "tags": [] - }, + "metadata": {}, "source": [ "You can use the following outline to get started." ] @@ -1460,9 +1429,7 @@ "cell_type": "code", "execution_count": 56, "id": "f377afbb", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "%%add_method_to Line\n", @@ -1480,20 +1447,13 @@ }, "outputs": [], "source": [ - "%%add_method_to Line\n", - "\n", - " def midpoint(self):\n", - " mid_x = (self.p1.x + self.p2.x) / 2\n", - " mid_y = (self.p1.y + self.p2.y) / 2\n", - " return Point(mid_x, mid_y)" + "# Solution goes here" ] }, { "cell_type": "markdown", "id": "4df69a9f", - "metadata": { - "tags": [] - }, + "metadata": {}, "source": [ "You can use the following examples to test your code and draw the result." ] @@ -1502,9 +1462,7 @@ "cell_type": "code", "execution_count": 58, "id": "0d603aa3", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "start = Point(0, 0)\n", @@ -1518,9 +1476,7 @@ "cell_type": "code", "execution_count": 59, "id": "647d0982", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "mid1 = line1.midpoint()\n", @@ -1531,9 +1487,7 @@ "cell_type": "code", "execution_count": 60, "id": "e351bea3", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "mid2 = line2.midpoint()\n", @@ -1544,9 +1498,7 @@ "cell_type": "code", "execution_count": 61, "id": "5ad5a076", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "line3 = Line(mid1, mid2)" @@ -1556,9 +1508,7 @@ "cell_type": "code", "execution_count": 62, "id": "8effaff0", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "make_turtle()\n", @@ -1580,9 +1530,7 @@ { "cell_type": "markdown", "id": "c586a3ed", - "metadata": { - "tags": [] - }, + "metadata": {}, "source": [ "You can use the following outline to get started." ] @@ -1591,9 +1539,7 @@ "cell_type": "code", "execution_count": 63, "id": "d94a6350", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "%%add_method_to Rectangle\n", @@ -1611,20 +1557,13 @@ }, "outputs": [], "source": [ - "%%add_method_to Rectangle\n", - "\n", - " def midpoint(self):\n", - " mid_x = self.corner.x + self.width / 2\n", - " mid_y = self.corner.y + self.height / 2\n", - " return Point(mid_x, mid_y)" + "# Solution goes here" ] }, { "cell_type": "markdown", "id": "d186c84b", - "metadata": { - "tags": [] - }, + "metadata": {}, "source": [ "You can use the following example to test your code." ] @@ -1633,9 +1572,7 @@ "cell_type": "code", "execution_count": 65, "id": "4aec759c", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "corner = Point(30, 20)\n", @@ -1646,9 +1583,7 @@ "cell_type": "code", "execution_count": 66, "id": "7ec3339d", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "mid = rectangle.midpoint()\n", @@ -1659,9 +1594,7 @@ "cell_type": "code", "execution_count": 67, "id": "326dbf24", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "diagonal = Line(corner, mid)" @@ -1671,9 +1604,7 @@ "cell_type": "code", "execution_count": 68, "id": "4da710d4", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "make_turtle()\n", @@ -1701,9 +1632,7 @@ { "cell_type": "markdown", "id": "29e994c6", - "metadata": { - "tags": [] - }, + "metadata": {}, "source": [ "You can use this outline to get started." ] @@ -1712,9 +1641,7 @@ "cell_type": "code", "execution_count": 69, "id": "30cc0726", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "%%add_method_to Rectangle\n", @@ -1732,24 +1659,13 @@ }, "outputs": [], "source": [ - "%%add_method_to Rectangle\n", - "\n", - " def make_cross(self):\n", - " midpoints = []\n", - "\n", - " for line in self.make_lines():\n", - " midpoints.append(line.midpoint())\n", - "\n", - " p1, p2, p3, p4 = midpoints\n", - " return Line(p1, p3), Line(p2, p4)" + "# Solution goes here" ] }, { "cell_type": "markdown", "id": "970fcbca", - "metadata": { - "tags": [] - }, + "metadata": {}, "source": [ "You can use the following example to test your code." ] @@ -1758,9 +1674,7 @@ "cell_type": "code", "execution_count": 71, "id": "2afd718c", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "corner = Point(30, 20)\n", @@ -1771,9 +1685,7 @@ "cell_type": "code", "execution_count": 72, "id": "b7bdb467", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "lines = rectangle.make_cross()" @@ -1783,9 +1695,7 @@ "cell_type": "code", "execution_count": 73, "id": "9d09b2c3", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "make_turtle()\n", @@ -1809,9 +1719,7 @@ { "cell_type": "markdown", "id": "cb1b24a3", - "metadata": { - "tags": [] - }, + "metadata": {}, "source": [ "You can use the following function, which is a version of the `circle` function we wrote in Chapter 4." ] @@ -1820,9 +1728,7 @@ "cell_type": "code", "execution_count": 74, "id": "b3d2328f", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "from jupyturtle import make_turtle, forward, left, right\n", @@ -1852,9 +1758,7 @@ { "cell_type": "markdown", "id": "b4325143", - "metadata": { - "tags": [] - }, + "metadata": {}, "source": [ "You can use the following example to test your code.\n", "We'll start with a square `Rectangle` with width and height `100`." @@ -1864,9 +1768,7 @@ "cell_type": "code", "execution_count": 76, "id": "49074ed5", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "corner = Point(20, 20)\n", @@ -1876,9 +1778,7 @@ { "cell_type": "markdown", "id": "2cdecfa9", - "metadata": { - "tags": [] - }, + "metadata": {}, "source": [ "The following code should create a `Circle` that fits inside the square." ] @@ -1887,9 +1787,7 @@ "cell_type": "code", "execution_count": 77, "id": "d65a9163", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "center = rectangle.midpoint()\n", @@ -1902,9 +1800,7 @@ { "cell_type": "markdown", "id": "37e94d98", - "metadata": { - "tags": [] - }, + "metadata": {}, "source": [ "If everything worked correctly, the following code should draw the circle inside the square (touching on all four sides)." ] @@ -1913,9 +1809,7 @@ "cell_type": "code", "execution_count": 78, "id": "e3b23b4d", - "metadata": { - "tags": [] - }, + "metadata": {}, "outputs": [], "source": [ "make_turtle(delay=0.01)\n", @@ -1924,14 +1818,6 @@ "circle.draw()" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "48abaaae", - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "markdown", "id": "a7f4edf8", diff --git a/chapters/chap17.ipynb b/chapters/chap17.ipynb index 7dadbc21..c26b8b78 100644 --- a/chapters/chap17.ipynb +++ b/chapters/chap17.ipynb @@ -1740,7 +1740,7 @@ "* `get_rank_counts` does the same thing with the ranks of the cards, returning a dictionary that maps from each rank code to the number of times it appears.\n", "\n", "All of the exercises that follow can be done using only the Python features we have learned so far, but some of them are more difficult than most of the previous exercises.\n", - "I encourage you to ask an AI for help.\n", + "I encourage you to ask a virtual assistant for help.\n", "\n", "For problems like this, it often works well to ask for general advice about strategies and algorithms.\n", "Then you can either write the code yourself or ask for code.\n", @@ -1934,7 +1934,7 @@ "Write a method called `has_straight` that checks whether a hand contains a straight, which is a set of five cards with consecutive ranks.\n", "For example, if a hand contains ranks `5`, `6`, `7`, `8`, and `9`, it contains a straight.\n", "\n", - "An Ace can come before a two or after a King, so `Ace`, `2`, `3`, `4`, `5` is a straight and so it `10`, `Jack`, `Queen`, `King`, `Ace`.\n", + "An Ace can come before a two or after a King, so `Ace`, `2`, `3`, `4`, `5` is a straight and so is `10`, `Jack`, `Queen`, `King`, `Ace`.\n", "But a straight cannot \"wrap around\", so `King`, `Ace`, `2`, `3`, `4` is not a straight." ] }, diff --git a/chapters/chap18.ipynb b/chapters/chap18.ipynb index 2cc91a57..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`." @@ -2013,7 +2013,6 @@ "### Ask a virtual assistant\n", "\n", "There are a few topics in this chapter you might want to learn about.\n", - "Here are some question to ask an AI.\n", "\n", "* \"What are the methods and operators of Python's set class?\"\n", "\n", @@ -2027,11 +2026,11 @@ "\n", "* \"How does `unittest` do test discovery?\"\n", "\n", - "\"Along with `assertEqual`, what are the most commonly used methods in `unittest.TestCase`?\"\n", + "* \"Along with `assertEqual`, what are the most commonly used methods in `unittest.TestCase`?\"\n", "\n", - "\"What are the pros and cons of `doctest` and `unittest`?\"\n", + "* \"What are the pros and cons of `doctest` and `unittest`?\"\n", "\n", - "For the following exercises, consider asking an AI for help, but as always, remember to test the results." + "For the following exercises, consider asking a virtual assistant for help, but as always, remember to test the results." ] }, { @@ -2064,7 +2063,7 @@ "metadata": {}, "source": [ "Write a version of this function that uses `set` operations instead of a `for` loop.\n", - "Hint: ask an AI \"How do I compute the intersection of Python sets?\"" + "Hint: ask a VA, \"How do I compute the intersection of Python sets?\"" ] }, { diff --git a/jb/_config.yml b/jb/_config.yml index 245575a9..f0b261f9 100644 --- a/jb/_config.yml +++ b/jb/_config.yml @@ -1,5 +1,5 @@ # Book settings -title: Think Python, 3rd edition +title: Think Python author: Allen B. Downey latex: @@ -14,6 +14,19 @@ repository: html: use_repository_button: true + extra_footer: | +
+ + Creative Commons License + +
+ This work is licensed under a + + Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License + . +
+ parse: # myst_extended_syntax: true # instead enable individual features below myst_enable_extensions: # https://myst-parser.readthedocs.io/en/latest/using/syntax-optional.html diff --git a/jb/_toc.yml b/jb/_toc.yml index e5e3fd4b..6a5c362e 100644 --- a/jb/_toc.yml +++ b/jb/_toc.yml @@ -1,23 +1,31 @@ format: jb-book root: index -chapters: -- file: chap00 -- file: chap01 -- file: chap02 -- file: chap03 -- file: chap04 -- file: chap05 -- file: chap06 -- file: chap07 -- file: chap08 -- file: chap09 -- file: chap10 -- file: chap11 -- file: chap12 -- file: chap13 -- file: chap14 -- file: chap15 -- file: chap16 -- file: chap17 -- file: chap18 -- file: chap19 +parts: +- caption: Front Matter + chapters: + - file: chap00 +- caption: Chapters + numbered: True + chapters: + - file: chap01 + - file: chap02 + - file: chap03 + - file: chap04 + - file: chap05 + - file: chap06 + - file: chap07 + - file: chap08 + - file: chap09 + - file: chap10 + - file: chap11 + - file: chap12 + - file: chap13 + - file: chap14 + - file: chap15 + - file: chap16 + - file: chap17 + - file: chap18 + - file: chap19 +- caption: End Matter + chapters: + - file: blank