From 823390175ede4e79f26ba91e958723235a6a6ba3 Mon Sep 17 00:00:00 2001 From: Alphonse-Brandon Date: Thu, 16 Mar 2023 16:29:54 +0100 Subject: [PATCH 1/2] Init --- python_masterclass/lessons/lesson1.ipynb | 235 +++-------------------- 1 file changed, 31 insertions(+), 204 deletions(-) diff --git a/python_masterclass/lessons/lesson1.ipynb b/python_masterclass/lessons/lesson1.ipynb index ac29948..e533742 100644 --- a/python_masterclass/lessons/lesson1.ipynb +++ b/python_masterclass/lessons/lesson1.ipynb @@ -9,86 +9,40 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n" - ] - } - ], + "outputs": [], "source": [ - "# Declare an integer variable\n", - "\n", - "age = 12\n", - "\n", - "print(type(age))" + "# Declare an integer variable\n" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 2, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n" - ] - } - ], + "outputs": [], "source": [ - "# Declare a float variable\n", - "\n", - "candidateHeight = 2.75\n", - "\n", - "print(type(candidateHeight))" + "# Declare a float variable\n" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n" - ] - } - ], + "outputs": [], "source": [ - "# Declare a string variable\n", - "\n", - "candidateName = 'Ken'\n", - "\n", - "print(type(candidateName))" + "# Declare a string variable\n" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 4, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n" - ] - } - ], + "outputs": [], "source": [ "# Declare a boolean variable\n", "\n", - "candidateAbsence = True\n", - "\n", - "print(type(candidateAbsence))\n" + "\n" ] }, { @@ -100,196 +54,69 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 5, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\n" - ] - } - ], + "outputs": [], "source": [ - "# Convert a string to an integer\n", - "\n", - "myName = \"Alphonse\"\n", - "age = 12\n", - "print(type(age))\n", - "\n", - "stringAge = str(age)\n", - "\n", - "print(type(stringAge))\n", - "\n", - "# print(f\"My name is {myName} and I am {age} old\")" + "# Convert a string to an integer\n" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 6, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2\n" - ] - } - ], + "outputs": [], "source": [ - "# Convert a float to an integer\n", - "\n", - "candidateHeight = 2.75\n", - "candidateHeightInMeters = int(candidateHeight)\n", - "print(candidateHeightInMeters)\n", - "\n" + "# Convert a float to an integer\n" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 7, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "# Convert an integer to a string\n", - "\n", - "yearOfBirth = 1983\n", - "yOB = str(yearOfBirth)\n", - "print(type(yearOfBirth))\n", - "\n", - "print(type(yOB))" + "\n" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { "vscode": { "languageId": "plaintext" } }, - "outputs": [], "source": [ "### Basic Operations" ] }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 9, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "£\n" - ] - }, - { - "ename": "TypeError", - "evalue": "unsupported operand type(s) for &: 'NoneType' and 'int'", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32md:\\GITHUBREPOSITORIES\\Python-Code-labs\\python_masterclass\\lessons\\lesson1.ipynb Cell 11\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 4\u001b[0m myBossSalary \u001b[39m=\u001b[39m \u001b[39m10000\u001b[39m\n\u001b[0;32m 6\u001b[0m \u001b[39m# print(mySalary + myBossSalary)\u001b[39;00m\n\u001b[1;32m----> 7\u001b[0m \u001b[39mprint\u001b[39;49m(\u001b[39m'\u001b[39;49m\u001b[39m£\u001b[39;49m\u001b[39m'\u001b[39;49m) \u001b[39m&\u001b[39;49m (mySalary \u001b[39m+\u001b[39;49m myBossSalary)\n", - "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for &: 'NoneType' and 'int'" - ] - } - ], + "outputs": [], "source": [ - "# Declare two integer variables and perform addition\n", - "\n", - "mySalary = 5000\n", - "myBossSalary = 10000\n", - "\n", - "# print(mySalary + myBossSalary)\n", - "print('£') & (mySalary + myBossSalary)" + "# Declare two integer variables and perform addition\n" ] }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 10, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "899.6400000000001\n", - "899.6400000000001\n" - ] - } - ], + "outputs": [], "source": [ - "# Declare two float variables and perform multiplication\n", - "\n", - "temperatureToday = 35.7\n", - "temperatureTomorrow = 25.2\n", - "\n", - "sumOfTemperature = temperatureToday * temperatureTomorrow\n", - "\n", - "print(sumOfTemperature)\n", - "\n", - "print(temperatureToday * temperatureTomorrow)" + "# Declare two float variables and perform multiplication\n" ] }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 11, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "BBC News\n", - "the nework name is BBC\n", - "The channel type is {}\n" - ] - }, - { - "ename": "AttributeError", - "evalue": "'NoneType' object has no attribute 'format'", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32md:\\GITHUBREPOSITORIES\\Python-Code-labs\\python_masterclass\\lessons\\lesson1.ipynb Cell 13\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[39mprint\u001b[39m(networkName \u001b[39m+\u001b[39m \u001b[39m'\u001b[39m\u001b[39m \u001b[39m\u001b[39m'\u001b[39m \u001b[39m+\u001b[39m channelType)\n\u001b[0;32m 8\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mthe nework name is \u001b[39m\u001b[39m{\u001b[39;00mnetworkName\u001b[39m}\u001b[39;00m\u001b[39m\"\u001b[39m)\n\u001b[1;32m---> 10\u001b[0m \u001b[39mprint\u001b[39;49m(\u001b[39m\"\u001b[39;49m\u001b[39mThe channel type is \u001b[39;49m\u001b[39m{}\u001b[39;49;00m\u001b[39m\"\u001b[39;49m)\u001b[39m.\u001b[39;49mformat(channelType)\n", - "\u001b[1;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'format'" - ] - } - ], + "outputs": [], "source": [ - "# Declare two string variables and perform concatenation\n", - "\n", - "networkName = 'BBC'\n", - "channelType = 'News'\n", - "\n", - "print(networkName + ' ' + channelType)\n", - "\n", - "print(f\"the nework name is {networkName}\")\n", - "\n" + "# Declare two string variables and perform concatenation\n" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { From 1268f92c56438704a93605ca3c9a30c7601a18fb Mon Sep 17 00:00:00 2001 From: fredericksoh <65475804+fredericksoh@users.noreply.github.com> Date: Thu, 23 Mar 2023 08:02:42 -0400 Subject: [PATCH 2/2] Co-authored-by: Alphonse Brandon --- python_masterclass/lessons/02_operators.ipynb | 281 ++++++++++++++---- 1 file changed, 231 insertions(+), 50 deletions(-) diff --git a/python_masterclass/lessons/02_operators.ipynb b/python_masterclass/lessons/02_operators.ipynb index ba100f6..209f523 100644 --- a/python_masterclass/lessons/02_operators.ipynb +++ b/python_masterclass/lessons/02_operators.ipynb @@ -9,74 +9,160 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ - "# Declare two variables" + "# Declare two variables\n", + "x = 2\n", + "y = 5\n" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "7" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Addition" + "# Addition\n", + "x + y" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "-3" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Subtraction" + "# Subtraction\n", + "x - y" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Multiplication" + "# Multiplication\n", + "x * y" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0.4" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Division" + "# Division\n", + "x / y" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Modulus" + "# Modulus\n", + "x % y " ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Integer Division" + "# Integer Division\n", + "x // y" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "32" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Exponentiation" + "# Exponential\n", + "x ** y " ] }, { @@ -88,65 +174,137 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ - "# Declare two variables" + "# Declare two variables\n", + "f = 3\n", + "g = 8" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ - "# Equal to" + "# Equal to\n", + "f = g" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ - "# Not equal to" + "f = 3" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Greater than" + "# Not equal to\n", + "f != g" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Less than" + "# Greater than\n", + "f > g" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 24, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Greater than or equal to" + "# Less than\n", + "f < g" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 25, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Less than or equal to" + "# Greater than or equal to\n", + "f >= g" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Less than or equal to\n", + "f <= g" ] }, { @@ -158,29 +316,52 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ - "# Declare three variables" + "# Declare three variables\n", + "s = 8\n", + "y = 9\n", + "z = 10\n" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 30, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Yes\n" + ] + } + ], "source": [ - "# Logical AND" + "# Logical AND\n", + "if s == 8 and y == 9:\n", + " print(\"Yes\")" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 29, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], "source": [ - "# Logical OR" + "# Logical OR \n", + "if s == 8 or y== 9: \n", + " print(\"True\")\n" ] }, { @@ -451,7 +632,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.6" + "version": "3.10.1" }, "orig_nbformat": 4, "vscode": {