From 6881f8599fab01332e83f4dc16cd7740cfbee75e Mon Sep 17 00:00:00 2001 From: HaetM Date: Fri, 22 Sep 2017 13:16:04 +0000 Subject: [PATCH 1/2] Completed as much as I could (: ! --- Functions.ipynb | 145 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 138 insertions(+), 7 deletions(-) diff --git a/Functions.ipynb b/Functions.ipynb index df58b4c..4c7bed5 100644 --- a/Functions.ipynb +++ b/Functions.ipynb @@ -67,6 +67,108 @@ "\n" ] }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1377" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "##add - takes 2 parameters: the two numbers to add, returns the sum\n", + "def add (number1, number2):\n", + " answer = number1+number2\n", + " return answer\n", + "add (45,6) " + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "30" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# subtract - takes 2 parameters: the two numbers to subtract, returns the difference\n", + "def add (number1, number2):\n", + " answer = number1-number2\n", + " return answer\n", + "abs(4-34)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "41" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "## floorDivide - takes 2 parameters: the two numbers to divide, returns the whole quotient\n", + "def add (number1, number2):\n", + " answer = number1-number2\n", + " return answer\n" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], + "source": [ + "def add (number1, number2):\n", + " answer = number//number2\n", + " return answer" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "ename": "IndentationError", + "evalue": "expected an indented block (, line 2)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m2\u001b[0m\n\u001b[0;31m functional (4,5,7)\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m expected an indented block\n" + ] + } + ], + "source": [ + "def functional(number1,number2):\n", + "functional (4,5,7)\n", + "assert add(5,2 == 7)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -102,7 +204,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "add(4,5)" @@ -111,7 +215,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "add(-6,-5)" @@ -119,9 +225,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'add' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\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[0madd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m5.6\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m9\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mNameError\u001b[0m: name 'add' is not defined" + ] + } + ], "source": [ "add(5.6, 9)" ] @@ -129,7 +247,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "add (\"hello\", \"world\") # ooops this is weird!!" @@ -170,10 +290,12 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ - "assert 2 + 2 == 5, \"Houston we've got a problem\" #This will give an AssertionError\n" + "assert 2 + 2 == 5, \"Houston we've got a problem\" #This will give an AssertionError" ] }, { @@ -187,6 +309,15 @@ "assert 2 + 2 == 4, \"Houston we've got a problem\" #this won't give an error!" ] }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [], + "source": [ + "assert 4 + 4 == 8" + ] + }, { "cell_type": "markdown", "metadata": {}, From 1c84611301449fe7b818c15efca974da0eb8aae8 Mon Sep 17 00:00:00 2001 From: HaetM Date: Tue, 26 Sep 2017 13:43:03 +0000 Subject: [PATCH 2/2] added functions --- Functions.ipynb | 287 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 191 insertions(+), 96 deletions(-) diff --git a/Functions.ipynb b/Functions.ipynb index 4c7bed5..4656a48 100644 --- a/Functions.ipynb +++ b/Functions.ipynb @@ -69,16 +69,16 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "1377" + "51" ] }, - "execution_count": 3, + "execution_count": 1, "metadata": {}, "output_type": "execute_result" } @@ -93,7 +93,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -102,14 +102,14 @@ "30" ] }, - "execution_count": 10, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# subtract - takes 2 parameters: the two numbers to subtract, returns the difference\n", - "def add (number1, number2):\n", + "def substract (number1, number2):\n", " answer = number1-number2\n", " return answer\n", "abs(4-34)" @@ -117,56 +117,77 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 3, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "41" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "## floorDivide - takes 2 parameters: the two numbers to divide, returns the whole quotient\n", - "def add (number1, number2):\n", + "def floorDivide (number1, number2):\n", " answer = number1-number2\n", - " return answer\n" + " return answer\n", + "floorDivide (34,5)" ] }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "scrolled": false + }, + "outputs": [], + "source": [ + "#divide - takes 2 parameters: the two numbers to divide, returns the quotient (as a decimal)\n", + "\n", + "def divite (number1, number2):\n", + " answer = number/number2\n", + " return answer\n", + "divide (10,2)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "def add (number1, number2):\n", - " answer = number//number2\n", - " return answer" + "# multiply - takes 2 parameters: the two numbers to multiply, returns the product\n", + "def multiply (number1, number2): \n", + " answer = number1 * number2\n", + " return answer\n", + "multiply (10,10)" ] }, { "cell_type": "code", - "execution_count": 38, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "IndentationError", - "evalue": "expected an indented block (, line 2)", - "output_type": "error", - "traceback": [ - "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m2\u001b[0m\n\u001b[0;31m functional (4,5,7)\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m expected an indented block\n" - ] - } - ], + "outputs": [], "source": [ - "def functional(number1,number2):\n", - "functional (4,5,7)\n", - "assert add(5,2 == 7)" + "# getRemainder - takes 2 parameters: the two numbers to divide, returns the remainder\n", + "def getRemainder (number1, number2): \n", + " answer = number1 % number2\n", + " return answer\n", + "getRemainder (10,53)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# power takes 2 parameters: the two numbers one is the base the other the power, returns base ^ power\n", + "def power (number1, number2): \n", + " answer = number1 ** number2\n", + " return answer\n", + "power(3,4)" ] }, { @@ -181,9 +202,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "#this function adds two numbers passed as parameters\n", @@ -204,9 +223,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "add(4,5)" @@ -215,9 +232,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "add(-6,-5)" @@ -225,21 +240,9 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'add' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\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[0madd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m5.6\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m9\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mNameError\u001b[0m: name 'add' is not defined" - ] - } - ], + "outputs": [], "source": [ "add(5.6, 9)" ] @@ -247,9 +250,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "add (\"hello\", \"world\") # ooops this is weird!!" @@ -290,9 +291,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert 2 + 2 == 5, \"Houston we've got a problem\" #This will give an AssertionError" @@ -301,9 +300,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert 2 + 2 == 4, \"Houston we've got a problem\" #this won't give an error!" @@ -311,7 +308,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -337,12 +334,124 @@ "power - takes 2 parameters: the two numbers one is the base the other the power, returns base ^ power\n" ] }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "#subtract - takes 2 parameters: the two numbers to subtract, returns the difference\n", + "def subtract (number1, number2):\n", + " answer = number1-number2\n", + " return answer\n", + "assert subtract(4,5)==-1, \"subtract function not working\"" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "ename": "AssertionError", + "evalue": "floor divide function not working", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAssertionError\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 3\u001b[0m \u001b[0manswer\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnumber1\u001b[0m \u001b[0;34m//\u001b[0m \u001b[0mnumber2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0manswer\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0;32massert\u001b[0m \u001b[0mfloorDivide\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m==\u001b[0m\u001b[0;36m0.5\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"floor divide function not working\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mAssertionError\u001b[0m: floor divide function not working" + ] + } + ], + "source": [ + "# floorDivide - takes 2 parameters: the two numbers to divide, returns the whole quotient\n", + "def floorDivide (number1, number2):\n", + " answer = number1 // number2\n", + " return answer\n", + "assert floorDivide(1,2)==0.5, \"floor divide function not working\" # actual answer is meant to be 0" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [], + "source": [ + "# divide - takes 2 parameters: the two numbers to divide, returns the quotient (as a decimal)\n", + "def divide (number1, number2):\n", + " answer = number1 / number2\n", + " return answer\n", + "assert divide(5,5)==1.0, \"divide function not working\"" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [], + "source": [ + "# multiply - takes 2 parameters: the two numbers to multiply, returns the product\n", + "def multiply (number1, number2):\n", + " answer = number1 * number2\n", + " return answer\n", + "assert multiply(4,5)==20, \"multiply function not working\"" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "ename": "AssertionError", + "evalue": "getRemainder function not working", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAssertionError\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 3\u001b[0m \u001b[0manswer\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnumber1\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mnumber2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0manswer\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0;32massert\u001b[0m \u001b[0mgetRemainder\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m==\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"getRemainder function not working\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mAssertionError\u001b[0m: getRemainder function not working" + ] + } + ], + "source": [ + "# getRemainder - takes 2 parameters: the two numbers to divide, returns the remainder\n", + "def getRemainder (number1, number2):\n", + " answer = number1 * number2\n", + " return answer\n", + "assert getRemainder(5,4)==1, \"getRemainder function not working\"" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "ename": "AssertionError", + "evalue": "power function not working", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAssertionError\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 2\u001b[0m \u001b[0manswer\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnumber1\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mnumber2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0manswer\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0;32massert\u001b[0m \u001b[0mpower\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m==\u001b[0m\u001b[0;36m9\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"power function not working\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mAssertionError\u001b[0m: power function not working" + ] + } + ], + "source": [ + "# power - takes 2 parameters: the two numbers one is the base the other the power, returns base ^ power\n", + "def power (number1, number2):\n", + " answer = number1 * number2\n", + " return answer\n", + "assert power(3,2)==9, \"power function not working\"" + ] + }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# subtract function \n", @@ -370,9 +479,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert add(4,5)==9, \"add function not working\"" @@ -381,9 +488,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert subtract(4,5)==-1, \"subtract function not working\"" @@ -392,9 +497,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert multiply(4,5)==20, \"multiply function not working\"" @@ -403,9 +506,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert divide(5,5)==1.0, \"divide function not working\"" @@ -414,9 +515,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert floorDivide(1,2)==0.5, \"floor divide function not working\"" @@ -425,9 +524,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert getRemainder(5,4)==1, \"getRemainder function not working\"" @@ -436,9 +533,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert power(3,2)==9, \"power function not working\""