From 033d90077c7f0bad28d9687e28b72cfd27768af8 Mon Sep 17 00:00:00 2001 From: yourusername Date: Thu, 28 Dec 2023 23:23:17 +0800 Subject: [PATCH] Fix-python-programming-advanced --- .../python-programming-advanced.ipynb | 221 ++++++------------ 1 file changed, 72 insertions(+), 149 deletions(-) diff --git a/open-machine-learning-jupyter-book/prerequisites/python-programming-advanced.ipynb b/open-machine-learning-jupyter-book/prerequisites/python-programming-advanced.ipynb index 1a3638fd1..05b0f75c3 100644 --- a/open-machine-learning-jupyter-book/prerequisites/python-programming-advanced.ipynb +++ b/open-machine-learning-jupyter-book/prerequisites/python-programming-advanced.ipynb @@ -107,7 +107,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": null, "id": "36014591", "metadata": { "attributes": { @@ -117,16 +117,7 @@ "id": "" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "You are a child!\n", - "You are an adult!\n" - ] - } - ], + "outputs": [], "source": [ "def get_age_group(age):\n", " if age >= 0 and age <= 9:\n", @@ -144,7 +135,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": null, "id": "31c3b613", "metadata": { "attributes": { @@ -157,21 +148,7 @@ "hide-input" ] }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "from IPython.display import HTML\n", "display(HTML(\"\"\"\n", @@ -197,7 +174,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": null, "id": "7a8f9150", "metadata": { "attributes": { @@ -228,7 +205,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": null, "id": "d5e08dd6", "metadata": { "attributes": { @@ -255,7 +232,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": null, "id": "e89b36d2", "metadata": { "attributes": { @@ -280,7 +257,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": null, "id": "794426df", "metadata": { "attributes": { @@ -310,7 +287,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": null, "id": "76f5393f", "metadata": { "attributes": { @@ -320,18 +297,7 @@ "id": "" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2\n", - "3\n", - "5\n", - "7\n" - ] - } - ], + "outputs": [], "source": [ "# find primes using a for-else construct\n", "for n in range(2, 10):\n", @@ -346,7 +312,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": null, "id": "14e6e08d", "metadata": { "attributes": { @@ -359,21 +325,7 @@ "hide-input" ] }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "from IPython.display import HTML\n", "display(HTML(\"\"\"\n", @@ -391,7 +343,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": null, "id": "4aaa9d4a", "metadata": { "attributes": { @@ -423,7 +375,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": null, "id": "5e381e96", "metadata": { "attributes": { @@ -453,7 +405,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": null, "id": "086272fd", "metadata": { "attributes": { @@ -487,7 +439,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": null, "id": "b703861b", "metadata": { "attributes": { @@ -523,7 +475,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": null, "id": "2af3dea8", "metadata": { "attributes": { @@ -562,7 +514,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": null, "id": "0e087b18", "metadata": { "attributes": { @@ -611,7 +563,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": null, "id": "c0a8f851", "metadata": { "attributes": { @@ -644,7 +596,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": null, "id": "d50416aa", "metadata": { "attributes": { @@ -677,7 +629,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": null, "id": "f05fce56", "metadata": { "attributes": { @@ -711,7 +663,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": null, "id": "df8ffa8f", "metadata": { "attributes": { @@ -751,7 +703,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": null, "id": "8d81d712", "metadata": { "attributes": { @@ -795,7 +747,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": null, "id": "e8e60c91", "metadata": { "attributes": { @@ -844,7 +796,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": null, "id": "16326504", "metadata": { "attributes": { @@ -900,7 +852,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": null, "id": "79fafb43", "metadata": { "attributes": { @@ -927,7 +879,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": null, "id": "046f84f4", "metadata": { "attributes": { @@ -955,7 +907,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": null, "id": "536a7942", "metadata": { "attributes": { @@ -985,7 +937,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": null, "id": "05673882", "metadata": { "attributes": { @@ -1017,7 +969,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": null, "id": "7fc8ec99", "metadata": { "attributes": { @@ -1049,7 +1001,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": null, "id": "c022ee5d", "metadata": { "attributes": { @@ -1083,7 +1035,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": null, "id": "08fd206b", "metadata": { "attributes": { @@ -1140,7 +1092,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": null, "id": "6ad97278", "metadata": { "attributes": { @@ -1166,7 +1118,7 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": null, "id": "7af77909", "metadata": { "attributes": { @@ -1229,7 +1181,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -1269,7 +1221,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": null, "id": "e9cbcbd8", "metadata": { "attributes": { @@ -1298,7 +1250,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": null, "id": "4ca6b4bb", "metadata": { "attributes": { @@ -1323,7 +1275,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": null, "id": "212905c0", "metadata": { "attributes": { @@ -1357,7 +1309,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": null, "id": "bc6d6b24", "metadata": { "attributes": { @@ -1445,6 +1397,10 @@ "source": [ "import pytest\n", "\n", + "def parrot(voltage, state='a stiff', action='voom'):\n", + " # Function implementation goes here\n", + " pass\n", + "\n", "# Required argument missing.\n", "with pytest.raises(Exception):\n", " # pylint: disable=no-value-for-parameter\n", @@ -1456,16 +1412,15 @@ " parrot(110, voltage=220)\n", "\n", "# Non-keyword argument after a keyword argument.\n", - "# Below code will result in SyntaxError as this.\n", - "# Cell In[45], line 18\n", - "# parrot(voltage=5.0, 'dead')\n", - "# SyntaxError: positional argument follows keyword argument\n", - "parrot(voltage=5.0, 'dead')\n", - "\n", + "# This will result in a TypeError due to the duplicate value for 'voltage'.\n", + "with pytest.raises(TypeError):\n", + " # pylint: disable=unexpected-keyword-arg,no-value-for-parameter\n", + " parrot('dead', voltage=5.0)\n", + " \n", "# Unknown keyword argument.\n", "with pytest.raises(Exception):\n", " # pylint: disable=unexpected-keyword-arg,no-value-for-parameter\n", - " parrot(actor='John Cleese')" + " parrot(actor='John Cleese')\n" ] }, { @@ -2832,18 +2787,10 @@ }, { "cell_type": "code", - "execution_count": 96, + "execution_count": null, "id": "b3399178", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Download: c:\\Users\\fuqiongying\\Desktop\\machine-learning\\open-machine-learning-jupyter-book\\prerequisites\\tmp\n" - ] - } - ], + "outputs": [], "source": [ "# Download the required module and package for this chapter\n", "\n", @@ -2914,34 +2861,10 @@ }, { "cell_type": "code", - "execution_count": 97, + "execution_count": null, "id": "b59ddec0", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['c:\\\\Users\\\\fuqiongying\\\\Desktop\\\\machine-learning\\\\open-machine-learning-jupyter-book\\\\prerequisites',\n", - " 'd:\\\\conda\\\\envs\\\\py39\\\\python39.zip',\n", - " 'd:\\\\conda\\\\envs\\\\py39\\\\DLLs',\n", - " 'd:\\\\conda\\\\envs\\\\py39\\\\lib',\n", - " 'd:\\\\conda\\\\envs\\\\py39',\n", - " '',\n", - " 'C:\\\\Users\\\\fuqiongying\\\\AppData\\\\Roaming\\\\Python\\\\Python39\\\\site-packages',\n", - " 'd:\\\\conda\\\\envs\\\\py39\\\\lib\\\\site-packages',\n", - " 'd:\\\\conda\\\\envs\\\\py39\\\\lib\\\\site-packages\\\\win32',\n", - " 'd:\\\\conda\\\\envs\\\\py39\\\\lib\\\\site-packages\\\\win32\\\\lib',\n", - " 'd:\\\\conda\\\\envs\\\\py39\\\\lib\\\\site-packages\\\\Pythonwin',\n", - " './tmp',\n", - " './tmp',\n", - " './tmp']" - ] - }, - "execution_count": 97, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "import sys\n", "sys.path.append(\"./tmp\")\n", @@ -2963,7 +2886,7 @@ }, { "cell_type": "code", - "execution_count": 98, + "execution_count": null, "id": "c76987ad", "metadata": { "attributes": { @@ -2988,7 +2911,7 @@ }, { "cell_type": "code", - "execution_count": 99, + "execution_count": null, "id": "80421e47", "metadata": { "attributes": { @@ -3016,7 +2939,7 @@ }, { "cell_type": "code", - "execution_count": 100, + "execution_count": null, "id": "fd0da443", "metadata": { "attributes": { @@ -3041,7 +2964,7 @@ }, { "cell_type": "code", - "execution_count": 101, + "execution_count": null, "id": "a46147ed", "metadata": { "attributes": { @@ -3070,7 +2993,7 @@ }, { "cell_type": "code", - "execution_count": 102, + "execution_count": null, "id": "517494d0", "metadata": { "attributes": { @@ -3102,7 +3025,7 @@ }, { "cell_type": "code", - "execution_count": 104, + "execution_count": null, "id": "0325d744", "metadata": { "attributes": { @@ -3128,7 +3051,7 @@ }, { "cell_type": "code", - "execution_count": 105, + "execution_count": null, "id": "69956cc5", "metadata": { "attributes": { @@ -3170,7 +3093,7 @@ }, { "cell_type": "code", - "execution_count": 107, + "execution_count": null, "id": "8d8a43f9", "metadata": { "attributes": { @@ -3195,7 +3118,7 @@ }, { "cell_type": "code", - "execution_count": 108, + "execution_count": null, "id": "dcb574c4", "metadata": { "attributes": { @@ -3221,7 +3144,7 @@ }, { "cell_type": "code", - "execution_count": 109, + "execution_count": null, "id": "ceb0daf7", "metadata": { "attributes": { @@ -3250,7 +3173,7 @@ }, { "cell_type": "code", - "execution_count": 110, + "execution_count": null, "id": "805c4ab0", "metadata": { "attributes": { @@ -3303,7 +3226,7 @@ }, { "cell_type": "code", - "execution_count": 111, + "execution_count": null, "id": "25901ef4", "metadata": { "attributes": { @@ -3337,7 +3260,7 @@ }, { "cell_type": "code", - "execution_count": 112, + "execution_count": null, "id": "5ddb3b1c", "metadata": { "attributes": { @@ -3372,7 +3295,7 @@ }, { "cell_type": "code", - "execution_count": 113, + "execution_count": null, "id": "3caec65a", "metadata": { "attributes": { @@ -3406,7 +3329,7 @@ }, { "cell_type": "code", - "execution_count": 114, + "execution_count": null, "id": "1b88ed8c", "metadata": { "attributes": { @@ -3443,7 +3366,7 @@ }, { "cell_type": "code", - "execution_count": 115, + "execution_count": null, "id": "a0922d13", "metadata": { "attributes": { @@ -3490,7 +3413,7 @@ }, { "cell_type": "code", - "execution_count": 116, + "execution_count": null, "id": "4a552e29", "metadata": { "attributes": { @@ -3528,7 +3451,7 @@ }, { "cell_type": "code", - "execution_count": 117, + "execution_count": null, "id": "f5b206da", "metadata": { "attributes": { @@ -3603,7 +3526,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.18" + "version": "3.11.4" } }, "nbformat": 4,