diff --git a/chapters/data-analytics/python-basic.ipynb b/chapters/data-analytics/python-basic.ipynb index 96e0cd1..56d35e9 100644 --- a/chapters/data-analytics/python-basic.ipynb +++ b/chapters/data-analytics/python-basic.ipynb @@ -378,7 +378,7 @@ "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "Input \u001b[0;32mIn [10]\u001b[0m, in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m hw1 \u001b[38;5;241m=\u001b[39m \u001b[43mh\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m \u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mw\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m2023\u001b[39;49m\n", + "Cell \u001b[0;32mIn[10], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m hw1 \u001b[38;5;241m=\u001b[39m \u001b[43mh\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m \u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mw\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m2023\u001b[39;49m\n", "\u001b[0;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str" ] } @@ -814,7 +814,7 @@ "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "Input \u001b[0;32mIn [22]\u001b[0m, in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m t1[\u001b[38;5;241m0\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n", + "Cell \u001b[0;32mIn[22], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m t1[\u001b[38;5;241m0\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n", "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" ] } @@ -1088,11 +1088,12 @@ "def sign(x): # Define a function with one argument x\n", " '''determine the sign of a single value'''\n", " if x > 0: # four blanks before each line within the function body\n", - " return 'positive' # another four blanks within `if` expressions\n", + " s = 'positive' # another four blanks within `if` expressions\n", " elif x < 0:\n", - " return 'negative'\n", + " s = 'negative'\n", " else:\n", - " return 'zero'\n", + " s = 'zero'\n", + " return s # Output of function\n", "\n", "for x in [-1, 0, 1]: \n", " print(\"{} is {}\".format(x, sign(x))) # Use parenthesis to run functions " @@ -1130,20 +1131,28 @@ "name": "stdout", "output_type": "stream", "text": [ - "Hello, Bob!\n", - "HELLO, FRED\n" + "-1 is negative\n", + "-1 is NEGATIVE\n" ] } ], "source": [ - "def hello(name, loud=False):\n", - " if loud:\n", - " print('HELLO, {}'.format(name.upper()))\n", + "def sign(x, upper=False): # Define a function with one argument x\n", + " '''determine the sign of a single value'''\n", + " if x > 0: # four blanks before each line within the function body\n", + " s = 'positive' # another four blanks within `if` expressions\n", + " elif x < 0:\n", + " s = 'negative'\n", + " else:\n", + " s = 'zero'\n", + " \n", + " if upper == True:\n", + " return s.upper()\n", " else:\n", - " print('Hello, {}!'.format(name))\n", + " return s\n", "\n", - "hello('Bob') # Without specific second argument, function would take default for it\n", - "hello('Fred', loud=True)" + "print(\"{} is {}\".format(-1, sign(-1))) # Without specific argument, function would take default for it\n", + "print(\"{} is {}\".format(-1, sign(-1, upper=True))) " ] }, { @@ -1159,11 +1168,14 @@ "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "-1\n" - ] + "data": { + "text/plain": [ + "-1" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ @@ -1327,7 +1339,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "\n", + "\n", "[1 2 3 4]\n" ] } @@ -1356,7 +1368,7 @@ "output_type": "stream", "text": [ "[1 2 3]\n", - "0.7186135151017801\n" + "0.5777723138166656\n" ] } ], @@ -1416,7 +1428,7 @@ " Whether to store multi-dimensional data in row-major\n", " (C-style) or column-major (Fortran-style) order in\n", " memory.\n", - " like : array_like\n", + " like : array_like, optional\n", " Reference object to allow the creation of arrays which are not\n", " NumPy arrays. If an array-like passed in as ``like`` supports\n", " the ``__array_function__`` protocol, the result will be defined\n", @@ -1477,7 +1489,7 @@ "Python can also be titled as an internet-based programming language, not only because of so many open-source third-party packages available online, but also due to actively engaged communities. [StackOverflow](https://stackoverflow.com) is a great Q&A website to search for similar questions from community buddies as you have. The answers supported most by community will show at first following the question.\n", "\n", "### Ask in ChatGPT\n", - "[ChatGPT](https://openai.com/blog/chatgpt) is an AI-powered language model developed by OpenAI. Prompted with proper questions, ChatGPT can give suggestions on code snippets that fit your demand. " + "[ChatGPT](https://openai.com/blog/chatgpt) is an AI-powered language model developed by OpenAI. Prompted with proper questions, ChatGPT can give suggestions on code snippets that fit your demand. You can also use the [GitHub Copilot](https://github.com/features/copilot) to autocomplete code lines." ] }, {