diff --git a/002-basic-control-structures/Basic control structures.ipynb b/002-basic-control-structures/Basic control structures.ipynb index 000b5a4..e614f8c 100644 --- a/002-basic-control-structures/Basic control structures.ipynb +++ b/002-basic-control-structures/Basic control structures.ipynb @@ -53,7 +53,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -97,22 +97,11 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "data": { - "text/plain": [ - "2" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "2 * x" ] @@ -154,18 +143,9 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Something else\n", - "0.6666666666666666\n" - ] - } - ], + "outputs": [], "source": [ "if Out[7] / 2 == x:\n", " print(\"Something else\")\n", @@ -246,17 +226,9 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Do I know you?\n" - ] - } - ], + "outputs": [], "source": [ "if (x < 2) or (x > 100):\n", " print(\"Do I know you?\")\n", @@ -320,7 +292,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -346,23 +318,13 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "fragment" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "I am 34 - am I old?\n", - "...checking if Phil is old...\n", - "Not at all, spring chicken.\n" - ] - } - ], + "outputs": [], "source": [ "phils_age = 34\n", "name = \"Phil\"\n", @@ -388,46 +350,27 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "slide" } }, - "outputs": [ - { - "data": { - "text/plain": [ - "'Just a normal string'" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "\"just a normal string\".capitalize()" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": { "scrolled": true, "slideshow": { "slide_type": "fragment" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The string was lowercase\n" - ] - } - ], + "outputs": [], "source": [ "if \"another string\".islower():\n", " print(\"The string was lowercase\")" @@ -469,7 +412,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -501,24 +444,9 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['Accept Nobel prize',\n", - " 'Finish PhD',\n", - " 'Inspire a new generation',\n", - " 'Learn Python',\n", - " 'Publish research']" - ] - }, - "execution_count": 24, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "sorted(things_to_do)" ] @@ -567,24 +495,13 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "fragment" } }, - "outputs": [ - { - "data": { - "text/plain": [ - "'Inspire a new generation'" - ] - }, - "execution_count": 26, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "things_to_do[4]" ] @@ -636,20 +553,9 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'In[3]'" - ] - }, - "execution_count": 33, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "In[32]" ] @@ -689,31 +595,13 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "fragment" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['Learn Python', 'Finish PhD', 'Publish research', 'Accept Nobel prize', 'Inspire a new generation']\n" - ] - }, - { - "data": { - "text/plain": [ - "['Finish PhD', 'Publish research', 'Accept Nobel prize']" - ] - }, - "execution_count": 35, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "print(things_to_do)\n", "things_to_do[1:4]" @@ -732,72 +620,39 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "fragment" } }, - "outputs": [ - { - "data": { - "text/plain": [ - "['Learn Python', 'Finish PhD']" - ] - }, - "execution_count": 36, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "things_to_do[:2]" ] }, { "cell_type": "code", - "execution_count": 37, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "fragment" } }, - "outputs": [ - { - "data": { - "text/plain": [ - "['Accept Nobel prize', 'Inspire a new generation']" - ] - }, - "execution_count": 37, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "things_to_do[3:]" ] }, { "cell_type": "code", - "execution_count": 38, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "fragment" } }, - "outputs": [ - { - "data": { - "text/plain": [ - "['Accept Nobel prize', 'Inspire a new generation']" - ] - }, - "execution_count": 38, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "things_to_do[-2:]" ] @@ -905,7 +760,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "fragment" @@ -947,28 +802,9 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "My favourite number is\n" - ] - }, - { - "ename": "KeyError", - "evalue": "'favourite numbe'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"My favourite number is\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mmy_meetup_dot_com_profile\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'favourite numbe'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mKeyError\u001b[0m: 'favourite numbe'" - ] - } - ], + "outputs": [], "source": [ "print(\"My favourite number is\")\n", "my_meetup_dot_com_profile['favourite numbe']" @@ -987,24 +823,13 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "fragment" } }, - "outputs": [ - { - "data": { - "text/plain": [ - "'is the magic number'" - ] - }, - "execution_count": 46, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "my_meetup_dot_com_profile[3]" ] @@ -1066,21 +891,11 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "TODO: ['Learn Python', 'Finish PhD', 'Publish research', 'Accept Nobel prize', 'Inspire a new generation', 'Find a nice retirement village in the Galapagos Islands'] \n", - "\n", - "MEETUP: {'first name': 'Ignatius', 'favourite number': 9, 'favourite programming language': 'FORTRAN66', 3: 'is the magic number', 'Interests': ['Python2', 'Python3', 'Scientific Python', 'Pottery']}\n" - ] - } - ], + "outputs": [], "source": [ "things_to_do.append(\"Find a nice retirement village in the Galapagos Islands\")\n", "\n", @@ -1107,20 +922,9 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['key1', 'key2', 'test', 'another_test']" - ] - }, - "execution_count": 50, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "from collections import OrderedDict # we'll discuss importing shortly\n", "\n", @@ -1164,24 +968,13 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "fragment" } }, - "outputs": [ - { - "data": { - "text/plain": [ - "'Learn Python, Finish PhD, Publish research, Accept Nobel prize, Inspire a new generation, Find a nice retirement village in the Galapagos Islands'" - ] - }, - "execution_count": 51, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "', '.join(things_to_do)" ] @@ -1258,18 +1051,9 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "When z is 1 then y is 120.0\n", - "When z is 3 then y is 40.0\n" - ] - } - ], + "outputs": [], "source": [ "y = 120\n", "for z in range(1, 5, 2):\n", @@ -1335,20 +1119,9 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "range" - ] - }, - "execution_count": 56, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "type(range(5))" ] @@ -1372,24 +1145,13 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "fragment" } }, - "outputs": [ - { - "data": { - "text/plain": [ - "[0, 1, 2, 3, 4]" - ] - }, - "execution_count": 58, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "list(range(5))" ] @@ -1418,41 +1180,18 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'range(0, 5)'" - ] - }, - "execution_count": 61, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "str(range(5))" ] }, { "cell_type": "code", - "execution_count": 57, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "TypeError", - "evalue": "unsupported operand type(s) for +: 'float' and 'str'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;36m3.14\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m\" is almost pi\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'float' and 'str'" - ] - } - ], + "outputs": [], "source": [ "3.14 + \" is almost pi\"" ] @@ -1470,20 +1209,9 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "str" - ] - }, - "execution_count": 62, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "type(str(3.14))" ] @@ -1501,17 +1229,9 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Let me hear you say Y.M.C.A. Let me hear you say Y.M.C.A. \n" - ] - } - ], + "outputs": [], "source": [ "lyric = \"\"\n", "for i in range(2):\n", @@ -1552,29 +1272,9 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learn Python :\n", - " using Python, this task will take 12 months to complete\n", - "Finish PhD :\n", - " using Python, this task will take 10 months to complete\n", - "Publish research :\n", - " using Python, this task will take 16 months to complete\n", - "Accept Nobel prize :\n", - " using Python, this task will take 18 months to complete\n", - "Inspire a new generation :\n", - " using Python, this task will take 24 months to complete\n", - "Find a nice retirement village in the Galapagos Islands :\n", - " using Python, this task will take 55 months to complete\n", - "You cannot retire for at least 11 years\n" - ] - } - ], + "outputs": [], "source": [ "total_months = 0\n", "for task in things_to_do:\n", @@ -1610,25 +1310,13 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "slide" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "first name\n", - "favourite number\n", - "favourite programming language\n", - "3\n", - "Interests\n" - ] - } - ], + "outputs": [], "source": [ "for field in my_meetup_dot_com_profile.keys():\n", " print(field)" @@ -1636,25 +1324,13 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "slide" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Ignatius\n", - "9\n", - "FORTRAN66\n", - "is the magic number\n", - "['Python2', 'Python3', 'Scientific Python', 'Pottery']\n" - ] - } - ], + "outputs": [], "source": [ "for value in my_meetup_dot_com_profile.values():\n", " print(value)" @@ -1662,25 +1338,13 @@ }, { "cell_type": "code", - "execution_count": 83, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "slide" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "first name = Ignatius\n", - "favourite number = 9\n", - "favourite programming language = FORTRAN66\n", - "3 = is the magic number\n", - "Interests = ['Python2', 'Python3', 'Scientific Python', 'Pottery']\n" - ] - } - ], + "outputs": [], "source": [ "for pair in my_meetup_dot_com_profile.items():\n", " print(pair[0], \"=\", pair[1])" @@ -1688,19 +1352,9 @@ }, { "cell_type": "code", - "execution_count": 86, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "key1 = 1 2 3\n", - "key2 = a b c\n", - "key3 = do re mi\n" - ] - } - ], + "outputs": [], "source": [ "my_dict = {'key1': [1, 2, 3], 'key2': ['a', 'b', 'c'], 'key3': ['do', 're', 'mi']}\n", "\n", @@ -1756,28 +1410,13 @@ }, { "cell_type": "code", - "execution_count": 94, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "notes" } }, - "outputs": [ - { - "data": { - "text/plain": [ - "{'first name': 'Ignatius',\n", - " 'favourite number': '9',\n", - " 'favourite programming language': 'FORTRAN66',\n", - " 3: 'is the magic number',\n", - " 'Interests': 'Python2, Python3, Scientific Python, Pottery'}" - ] - }, - "execution_count": 94, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "def dict_to_string_map(dct):\n", " new_dct = {}\n", @@ -1830,20 +1469,9 @@ }, { "cell_type": "code", - "execution_count": 100, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{1: 'one', 2: 'two', 3: 'three'}" - ] - }, - "execution_count": 100, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "new_dct = {}\n", "for key, value in zip(keys, values):\n", @@ -1853,20 +1481,9 @@ }, { "cell_type": "code", - "execution_count": 101, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{1: 'one', 2: 'two', 3: 'three'}" - ] - }, - "execution_count": 101, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "dict(zip(keys, values))" ] @@ -1992,7 +1609,7 @@ }, { "cell_type": "code", - "execution_count": 102, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "-" @@ -2027,24 +1644,13 @@ }, { "cell_type": "code", - "execution_count": 103, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "-" } }, - "outputs": [ - { - "data": { - "text/plain": [ - "3.141592653589793" - ] - }, - "execution_count": 103, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "math.pi" ] @@ -2062,22 +1668,11 @@ }, { "cell_type": "code", - "execution_count": 104, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "data": { - "text/plain": [ - "1.0" - ] - }, - "execution_count": 104, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "math.sin(math.pi / 2)" ] @@ -2118,17 +1713,9 @@ }, { "cell_type": "code", - "execution_count": 107, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n" - ] - } - ], + "outputs": [], "source": [ "import os\n", "print(os.path.exists('/usr/bin/python'))" @@ -2158,17 +1745,9 @@ }, { "cell_type": "code", - "execution_count": 108, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['/home/jovyan/python-course/002-basic-control-structures', '/opt/conda/lib/python37.zip', '/opt/conda/lib/python3.7', '/opt/conda/lib/python3.7/lib-dynload', '', '/opt/conda/lib/python3.7/site-packages', '/opt/conda/lib/python3.7/site-packages/IPython/extensions', '/home/jovyan/.ipython']\n" - ] - } - ], + "outputs": [], "source": [ "import sys\n", "print(sys.path)\n", @@ -2201,22 +1780,14 @@ }, { "cell_type": "code", - "execution_count": 109, + "execution_count": null, "metadata": { "scrolled": true, "slideshow": { "slide_type": "fragment" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2.718281828459045\n" - ] - } - ], + "outputs": [], "source": [ "import math\n", "print(math.e)" @@ -2235,21 +1806,13 @@ }, { "cell_type": "code", - "execution_count": 114, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "fragment" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2.718281828459045\n" - ] - } - ], + "outputs": [], "source": [ "import math as m\n", "print(m.e)" @@ -2268,21 +1831,13 @@ }, { "cell_type": "code", - "execution_count": 115, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "fragment" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2.718281828459045\n" - ] - } - ], + "outputs": [], "source": [ "from math import e\n", "print(e)" @@ -2301,21 +1856,13 @@ }, { "cell_type": "code", - "execution_count": 119, + "execution_count": null, "metadata": { "slideshow": { "slide_type": "fragment" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "sin(3)\n" - ] - } - ], + "outputs": [], "source": [ "from math import *\n", "from sympy import *\n", @@ -2521,22 +2068,9 @@ }, { "cell_type": "code", - "execution_count": 120, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learn Python\n", - "Finish PhD\n", - "Publish research\n", - "Accept Nobel prize\n", - "Inspire a new generation\n", - "Find a nice retirement village in the Galapagos Islands\n" - ] - } - ], + "outputs": [], "source": [ "for i in range(len(things_to_do)):\n", " print(things_to_do[i])" @@ -2555,22 +2089,9 @@ }, { "cell_type": "code", - "execution_count": 121, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learn Python\n", - "Finish PhD\n", - "Publish research\n", - "Accept Nobel prize\n", - "Inspire a new generation\n", - "Find a nice retirement village in the Galapagos Islands\n" - ] - } - ], + "outputs": [], "source": [ "for task in things_to_do:\n", " print(task)" @@ -2596,37 +2117,9 @@ }, { "cell_type": "code", - "execution_count": 122, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The Zen of Python, by Tim Peters\n", - "\n", - "Beautiful is better than ugly.\n", - "Explicit is better than implicit.\n", - "Simple is better than complex.\n", - "Complex is better than complicated.\n", - "Flat is better than nested.\n", - "Sparse is better than dense.\n", - "Readability counts.\n", - "Special cases aren't special enough to break the rules.\n", - "Although practicality beats purity.\n", - "Errors should never pass silently.\n", - "Unless explicitly silenced.\n", - "In the face of ambiguity, refuse the temptation to guess.\n", - "There should be one-- and preferably only one --obvious way to do it.\n", - "Although that way may not be obvious at first unless you're Dutch.\n", - "Now is better than never.\n", - "Although never is often better than *right* now.\n", - "If the implementation is hard to explain, it's a bad idea.\n", - "If the implementation is easy to explain, it may be a good idea.\n", - "Namespaces are one honking great idea -- let's do more of those!\n" - ] - } - ], + "outputs": [], "source": [ "import this" ] @@ -2872,7 +2365,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.7.6" }, "livereveal": { "theme": "beige",