From b942d1029a183b51203d6092b27cc74bef4a73a2 Mon Sep 17 00:00:00 2001 From: Michael Dereszynski Date: Wed, 8 Jul 2020 18:09:56 +0000 Subject: [PATCH] update for initial release --- .gitignore | 4 +- Coding Challenges-answers.ipynb | 334 ------------------------ notebooks/1-Introduction.ipynb | 418 ++++++++++++++++++++++++++---- notebooks/2-Flow_Control.ipynb | 65 +---- notebooks/3-Functions.ipynb | 72 +++-- notebooks/Coding_Challenges.ipynb | 22 +- src/challenge_tests.py | 32 ++- 7 files changed, 484 insertions(+), 463 deletions(-) delete mode 100644 Coding Challenges-answers.ipynb diff --git a/.gitignore b/.gitignore index 007ea85..a2ba029 100644 --- a/.gitignore +++ b/.gitignore @@ -138,4 +138,6 @@ dmypy.json cython_debug/ # Removing the vs code Dev stuff -.devcontainer/ \ No newline at end of file +.devcontainer/ +# Also removing the answers from the public repo +coding challenges-answers.ipynb \ No newline at end of file diff --git a/Coding Challenges-answers.ipynb b/Coding Challenges-answers.ipynb deleted file mode 100644 index 234e6ea..0000000 --- a/Coding Challenges-answers.ipynb +++ /dev/null @@ -1,334 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "%run ./src/challenge_tests.py" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Coding Challenges\n", - "Now it's time to put all you have learned together to try some unique coding puzzles. The coding challenges presented here range from very easy to challenging. For each one there are few hints that you can use if you get stuck. Each challenge has a space for you to write the answer and a cell following which can be executed to check your answer against a few test cases." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Challenge 1 - What day of the year is it?" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[32mTest Jan 1, 2000: pass\tResult: 1. Expected 1.\u001b[0m\n", - "\u001b[32mTest Feb 2, 2015: pass\tResult: 46. Expected 46.\u001b[0m\n", - "\u001b[32mTest June 30, 2020: pass\tResult: 182. Expected 182.\u001b[0m\n" - ] - } - ], - "source": [ - "def day_of_year(day, month, year):\n", - " ''' A function to determine what day of the year it is\n", - " Parameters\n", - " ----------\n", - " day : int\n", - " The day of the month\n", - " month : int\n", - " The month of the year\n", - " year : int\n", - " The year which the day is being calculated\n", - " '''\n", - " days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n", - " total_days = day\n", - " for m in range(month -1):\n", - " total_days = total_days+days_in_month[m]\n", - " if (month > 2) and is_leap_year(year):\n", - " total_days = total_days + 1\n", - " \n", - " return total_days\n", - "\n", - "def is_leap_year(y):\n", - " return (y % 4 == 0) and ((y % 100 != 0) or (y % 400 == 0))\n", - "\n", - "assert_equal(day_of_year(1,1,2000),1,'Jan 1, 2000')\n", - "assert_equal(day_of_year(15,2,2015),46,'Feb 2, 2015')\n", - "assert_equal(day_of_year(30,6,2020),182,'June 30, 2020', 'Did you check for leap year?')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Challenge 2 - Create me a monogram" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[32mTest : pass\tResult: d.S.k. Expected d.S.k.\u001b[0m\n", - "\u001b[32mTest : pass\tResult: e.D.s. Expected e.D.s.\u001b[0m\n", - "\u001b[32mTest : pass\tResult: m.B.s. Expected m.B.s.\u001b[0m\n" - ] - } - ], - "source": [ - "def monogram(full_name):\n", - " '''\n", - " Creates a traditional monogram from a supplied full name\n", - " '''\n", - " first, middle, last = full_name.split(' ',2)\n", - " return f'{first[0].lower()}.{last[0].upper()}.{middle[0].lower()}'\n", - "\n", - "# Basic tests\n", - "assert_equal(monogram('Dwight Kevin Shrute'),'d.S.k')\n", - "assert_equal(monogram('Eye see deadpeople'),'e.D.s', hint='Did you check the case?')\n", - "assert_equal(monogram('mers sadees benz II'),'m.B.s',hint='Did the extra suffix throw you off?')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Challenge 3 - Are you my mother?" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[32mTest : pass\tResult: Daughter. Expected Daughter.\u001b[0m\n", - "\u001b[32mTest : pass\tResult: Sister. Expected Sister.\u001b[0m\n" - ] - } - ], - "source": [ - "def relations(family_tree, relationship):\n", - " ''' Determine the relationship between two people in a given family\n", - " \n", - " Parameters\n", - " ----------\n", - " family_tree : list of tuple of str\n", - " The family tree is defined by tuples of mother/daughter pairs \n", - " where the first item in the tuple is the mother of the second name in the tuple.\n", - " relationship: tuple of str\n", - " The relationship to be determined of the second person in the tuple to the first person in the tuple\n", - " \n", - " Returns\n", - " -------\n", - " str : {'Grandmother','Granddaughter','Mother','Daughter','Sister','Cousin','Aunt','Niece'}\n", - " The relationship of the second person in the `relationship` tuple to the first person in the tuple\n", - " \n", - " '''\n", - " # Replace pass with your code\n", - " parents = {}\n", - " for parent, child in family_tree:\n", - " # Build a list of children by specifying the parent\n", - " parents[child] = parent\n", - " \n", - " # Now get the targets\n", - " gen_1 = relationship[0]\n", - " gen_2 = relationship[1]\n", - " \n", - " gen_1_parent = parents.get(gen_1)\n", - " gen_1_parent_parent = parents.get(gen_1_parent)\n", - " gen_2_parent = parents.get(gen_2)\n", - " gen_2_parent_parent = parents.get(gen_2_parent)\n", - " \n", - " if gen_2 == gen_1_parent : return 'Mother'\n", - " if gen_2 == gen_1_parent_parent : return 'Grandmother'\n", - " if gen_1 == gen_2_parent : return 'Daughter'\n", - " if gen_1 == gen_2_parent_parent : return 'Granddaughter'\n", - " if gen_1_parent == gen_2_parent : return 'Sister'\n", - " if gen_1_parent_parent == gen_2_parent_parent : return 'Cousin'\n", - " if gen_1_parent_parent == gen_2_parent : return 'Aunt'\n", - " if gen_1_parent == gen_2_parent_parent : return 'Niece'\n", - " \n", - "# Run this cell to test your work\n", - "family_a = [(\"Enid\", \"Susan\"), (\"Susan\", \"Deborah\")]\n", - "family_b = [('Enid', 'Susan'), ('Susan', 'Deborah'), ('Enid', 'Dianne'), ('Dianne', 'Judy'), ('Dianne', 'Fern')]\n", - "\n", - "assert_equal(relations(family_a,('Enid','Susan')),'Daughter')\n", - "assert_equal(relations(family_b,('Enid','Judy')),'Sister')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Challenge 4 - Money in the bank" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[32mTest : pass\tResult: 4. Expected 4.\u001b[0m\n", - "\u001b[32mTest : pass\tResult: -1. Expected -1.\u001b[0m\n", - "\u001b[32mTest : pass\tResult: 6. Expected 6.\u001b[0m\n", - "\u001b[32mTest : pass\tResult: 5. Expected 5.\u001b[0m\n", - "\u001b[32mTest : pass\tResult: 3. Expected 3.\u001b[0m\n", - "\u001b[32mTest : pass\tResult: 20. Expected 20.\u001b[0m\n" - ] - } - ], - "source": [ - "def dispense_cash(amount):\n", - " ''' Determine the minimum number of ATM bills to meet the requested amount to dispense\n", - " \n", - " Parameters\n", - " ----------\n", - " amount : int\n", - " The amount of money requested from the ATM\n", - " \n", - " Returns\n", - " -------\n", - " int\n", - " The number of bills needed, -1 if it can't be done\n", - " '''\n", - " total_bills = 0\n", - " if amount % 10 != 0:\n", - " return -1 # Can't be done, because it has to be a multiple of 10\n", - " \n", - " b_500 = (amount // 500) # The // operator does integer only division - such that 4 // 3 = 1\n", - " b_100 = (amount % 500) // 100\n", - " b_50 = (amount - (b_500*500) - (b_100 *100)) // 50\n", - " b_20 = (amount - (b_500*500) - (b_100 *100) - (b_50 * 50)) // 20\n", - " b_10 = (amount - (b_500*500) - (b_100 *100) - (b_50 * 50) - (b_20 * 20)) // 10\n", - " \n", - " total_bills = b_500 + b_100 + b_50 + b_20 + b_10\n", - " return total_bills\n", - "\n", - "assert_equal(dispense_cash(1120), 4)\n", - "assert_equal(dispense_cash(492), -1)\n", - "assert_equal(dispense_cash(440), 6)\n", - "assert_equal(dispense_cash(370), 5)\n", - "assert_equal(dispense_cash(80), 3)\n", - "assert_equal(dispense_cash(8720), 20)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Challenge 5 - Fruit Calculator" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[32mTest : pass\tResult: 6. Expected 6.\u001b[0m\n", - "\u001b[32mTest : pass\tResult: 5. Expected 5.\u001b[0m\n", - "\u001b[32mTest : pass\tResult: 8. Expected 8.\u001b[0m\n", - "\u001b[32mTest : pass\tResult: 12. Expected 12.\u001b[0m\n", - "\u001b[32mTest : pass\tResult: 0. Expected 0.\u001b[0m\n" - ] - } - ], - "source": [ - "def fruit_calculator(question):\n", - " # Set the quantity to zero\n", - " # For each word in the string\n", - " # If the word is 'loses', then we are going to be subtracting\n", - " # If the word is a number, then convert it to an integer, if the \n", - " # If the previous word was a number (the value of number is not zero),\n", - " # then add this word to a dictionary as a key and add the number to the value\n", - " # Find the last word, remove the '?' and look it up in dictionary - this is the value\n", - " \n", - " # Set the qty to zero\n", - " qty = 0 \n", - " lose = False\n", - " fruits = {}\n", - " words = question.split(' ')\n", - " # For each word in the string\n", - " for w in words:\n", - " \n", - " # Since the split may include `.` or `,` we need to take these off\n", - " w = w.rstrip('.').rstrip(',')\n", - " if w == 'loses':\n", - " lose = True\n", - " \n", - " # If the word is a number, then figure out if this is a gain, loss or just has\n", - " if w.isdigit():\n", - " qty = int(w)\n", - " # Gains and Loses is 0 if there hasn't been a gain or loss\n", - " if lose:\n", - " qty = qty * -1\n", - " # Need to reset the lose value to False\n", - " lose = False\n", - " \n", - " else:\n", - " # If the previous word was a number (the value of qty is not zero),\n", - " # then add this word to a dictionary as a key and add the number to the value\n", - " if qty != 0:\n", - " fruits[w] = fruits.get(w,0) + qty\n", - " qty = 0\n", - " \n", - " # Find the last word, remove the '?' and look it up in dictionary - this is the value\n", - " target_fruit = words[-1].rstrip('?')\n", - " return fruits.get(target_fruit,0)\n", - "\n", - "assert_equal(fruit_calculator('Panda has 8 apples and loses 2 apples. How many apples?'), 6)\n", - "assert_equal(fruit_calculator('Panda has 8 apples, 2 bananas and gains 3 bananas. How many bananas?'), 5)\n", - "assert_equal(fruit_calculator('Panda has 8 apples, 2 bananas and gains 3 bananas. How many apples?'), 8) \n", - "assert_equal(fruit_calculator('Jim has 12 bananas. He loses 2 apples. Then he gains 1 apple. How many bananas?'),12)\n", - "assert_equal(fruit_calculator('Jim has 2 bananas and gains 3 bananas. How many watermelons?'),0)" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.5" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/notebooks/1-Introduction.ipynb b/notebooks/1-Introduction.ipynb index 6785c18..9db6288 100644 --- a/notebooks/1-Introduction.ipynb +++ b/notebooks/1-Introduction.ipynb @@ -1,5 +1,15 @@ { "cells": [ + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "from IPython.core.interactiveshell import InteractiveShell\n", + "InteractiveShell.ast_node_interactivity = \"all\"" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -15,9 +25,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 1, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "Welcome to Jupyter. You have successfully run a code cell.\n" + } + ], "source": [ "print('Welcome to Jupyter. You have successfully run a code cell.')" ] @@ -81,9 +99,26 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "4" + }, + "metadata": {}, + "execution_count": 13 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "15105" + }, + "metadata": {}, + "execution_count": 13 + } + ], "source": [ "2+2\n", "53*285" @@ -98,9 +133,34 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "30" + }, + "metadata": {}, + "execution_count": 14 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "50" + }, + "metadata": {}, + "execution_count": 14 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "50" + }, + "metadata": {}, + "execution_count": 14 + } + ], "source": [ "5+5*5 # This equals 30 because 5*5 happens first (order of precidence)\n", "(5+5)*5 # This evaluates to 50 because we have told Python to add first due to parenthesis\n", @@ -148,9 +208,18 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "60" + }, + "metadata": {}, + "execution_count": 15 + } + ], "source": [ "width = 5\n", "height = 12\n", @@ -170,9 +239,65 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 16, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "'spam eggs'" + }, + "metadata": {}, + "execution_count": 16 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "\"doesn't\"" + }, + "metadata": {}, + "execution_count": 16 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "\"doesn't\"" + }, + "metadata": {}, + "execution_count": 16 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "'\"Yes,\" they said.'" + }, + "metadata": {}, + "execution_count": 16 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "'\"Yes,\" they said.'" + }, + "metadata": {}, + "execution_count": 16 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "'\"Isn\\'t,\" they said.'" + }, + "metadata": {}, + "execution_count": 16 + }, + { + "output_type": "stream", + "name": "stdout", + "text": "spam eggs\n\"Yes,\" they said.\n" + } + ], "source": [ "'spam eggs' # single quotes\n", "'doesn\\'t' # use \\' to escape the single quote...\n", @@ -194,9 +319,50 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "'Hello World!'" + }, + "metadata": {}, + "execution_count": 17 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "'4 + 3 = 7'" + }, + "metadata": {}, + "execution_count": 17 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "'4 + 3 = 7'" + }, + "metadata": {}, + "execution_count": 17 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "'Hello World!'" + }, + "metadata": {}, + "execution_count": 17 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "'Line 1 is on the same line as Line 2'" + }, + "metadata": {}, + "execution_count": 17 + } + ], "source": [ "'Hello '+'World!' # Two strings concatenated together\n", "'4 + 3 = ' + str(7) # We need to tell Python this is supposed to be a string\n", @@ -231,9 +397,26 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "\"Hi, my name is Joe. What's your name?\"" + }, + "metadata": {}, + "execution_count": 18 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "'Calculating stuff is easy too, see 4+8 = 12'" + }, + "metadata": {}, + "execution_count": 18 + } + ], "source": [ "#Try it!\n", "my_name = 'Joe'\n", @@ -258,7 +441,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -277,9 +460,26 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "[1, 4, 9, 16, 25, 36]" + }, + "metadata": {}, + "execution_count": 20 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "['Alice', 'Bob', 'Charlie']" + }, + "metadata": {}, + "execution_count": 20 + } + ], "source": [ "squares = [1,4,9,16,25,36] # This is a list of squares\n", "people = ['Alice', 'Bob', 'Charlie'] # this is a list of people's names\n", @@ -296,9 +496,58 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "1" + }, + "metadata": {}, + "execution_count": 21 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "36" + }, + "metadata": {}, + "execution_count": 21 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "[1, 4]" + }, + "metadata": {}, + "execution_count": 21 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "[1, 9, 25]" + }, + "metadata": {}, + "execution_count": 21 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "[1, 9, 25]" + }, + "metadata": {}, + "execution_count": 21 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "[1, 4]" + }, + "metadata": {}, + "execution_count": 21 + } + ], "source": [ "squares[0] # Returns the first item in the list of integers called squares\n", "squares[-1] # Returns the last item in the list\n", @@ -317,9 +566,18 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "[1, 4, 9, 16, 25, 36, 49, 64, 81]" + }, + "metadata": {}, + "execution_count": 22 + } + ], "source": [ "squares + [49,64,81]" ] @@ -333,9 +591,26 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "\"Names before the change: ['Alice', 'Bob', 'Charlie']\"" + }, + "metadata": {}, + "execution_count": 23 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "\"Names after the change: ['Alice', 'Bonita', 'Charlie']\"" + }, + "metadata": {}, + "execution_count": 23 + } + ], "source": [ "f'Names before the change: {people}'\n", "people[1] = 'Bonita'\n", @@ -351,9 +626,26 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "3" + }, + "metadata": {}, + "execution_count": 24 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "6" + }, + "metadata": {}, + "execution_count": 24 + } + ], "source": [ "len(people)\n", "len(squares)" @@ -368,9 +660,34 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "[['a', 'b', 'c'], [1, 2, 3]]" + }, + "metadata": {}, + "execution_count": 25 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "['a', 'b', 'c']" + }, + "metadata": {}, + "execution_count": 25 + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "'b'" + }, + "metadata": {}, + "execution_count": 25 + } + ], "source": [ "n = [1,2,3]\n", "a = ['a','b','c']\n", @@ -390,9 +707,18 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "'Ellipsis EllipsisEllipsis'" + }, + "metadata": {}, + "execution_count": 26 + } + ], "source": [ "# Don't change this declaration directly, instead just manipulate the output by putting the correct\n", "# in place of the ellipsis `...`\n", @@ -417,9 +743,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3.7.1 64-bit", + "display_name": "Python 3.7.6 64-bit ('base': conda)", "language": "python", - "name": "python37164bitadc83be799394474a1958ce4aebca0f6" + "name": "python_defaultSpec_1594132474756" }, "language_info": { "codemirror_mode": { @@ -465,4 +791,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file diff --git a/notebooks/2-Flow_Control.ipynb b/notebooks/2-Flow_Control.ipynb index fe1412b..bd591d5 100644 --- a/notebooks/2-Flow_Control.ipynb +++ b/notebooks/2-Flow_Control.ipynb @@ -1,14 +1,5 @@ { "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%run ../src/utils.py" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -20,7 +11,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "a, b = 0, 1 # Here are just initializing the variables a and b to 0 and 1 respectively\n", @@ -55,7 +48,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "x = int(input(\"Please enter integer\"))\n", @@ -115,7 +110,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# Here's another fun example\n", @@ -166,46 +163,6 @@ "# print the new string" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "jupyter": { - "source_hidden": true - } - }, - "outputs": [], - "source": [ - "# This is the word for which you should be replacing the vowels\n", - "alphabet = 'abcdefghijklmnopqrstuvwxyz'\n", - "\n", - "# create a variable to hold the new set of letters\n", - "letters = ''\n", - "# for each letter in the word provided\n", - "for l in alphabet:\n", - " # if the letter is an `a` then add a captial `A` to the new set of letters\n", - " if l == 'a':\n", - " letters = letters + 'A'\n", - " # otherwise if the letter is an `e` then add a capital `E` to the new set of letters\n", - " elif l == 'e':\n", - " letters = letters + 'E'\n", - " # otherwise if the letter is an `i` then add a capital `I` to the new set of letters\n", - " elif l == 'i':\n", - " letters = letters + 'I'\n", - " # otherwise if the letter is an `e` then add a capital `O` to the new set of letters\n", - " elif l == 'o':\n", - " letters = letters + 'O'\n", - " # otherwise if the letter is an `e` then add a capital `U` to the new set of letters\n", - " elif l == 'u':\n", - " letters = letters + 'U'\n", - " # otherwise add the current letter to the new set of letters\n", - " else:\n", - " letters = letters + l\n", - "\n", - "# print out the new string\n", - "letters" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -305,7 +262,7 @@ " update_screen()\n", "``` \n", "\n", - "In the next section, we'll focus on how to break our code into steps that both make it more readable and reusable by creating _functions_" + "In the next [section](3-Fuctions.ipynb), we'll focus on how to break our code into steps that both make it more readable and reusable by creating _functions_" ] } ], @@ -330,4 +287,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file diff --git a/notebooks/3-Functions.ipynb b/notebooks/3-Functions.ipynb index 25ae2b5..2ffe09d 100644 --- a/notebooks/3-Functions.ipynb +++ b/notebooks/3-Functions.ipynb @@ -92,10 +92,24 @@ "## Best Practices\n", "There are a few things that should be considered when creating functions in any language and a few things that are specfic to Python.\n", "