diff --git a/Functions.ipynb b/Functions.ipynb index df58b4c..4656a48 100644 --- a/Functions.ipynb +++ b/Functions.ipynb @@ -67,6 +67,129 @@ "\n" ] }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "51" + ] + }, + "execution_count": 1, + "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": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "30" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# subtract - takes 2 parameters: the two numbers to subtract, returns the difference\n", + "def substract (number1, number2):\n", + " answer = number1-number2\n", + " return answer\n", + "abs(4-34)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "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", + "floorDivide (34,5)" + ] + }, + { + "cell_type": "code", + "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": [ + "# 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": null, + "metadata": {}, + "outputs": [], + "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", + "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)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -79,9 +202,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "#this function adds two numbers passed as parameters\n", @@ -173,20 +294,27 @@ "metadata": {}, "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" ] }, { "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!" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "assert 4 + 4 == 8" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -206,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", @@ -239,9 +479,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert add(4,5)==9, \"add function not working\"" @@ -250,9 +488,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert subtract(4,5)==-1, \"subtract function not working\"" @@ -261,9 +497,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert multiply(4,5)==20, \"multiply function not working\"" @@ -272,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\"" @@ -283,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\"" @@ -294,9 +524,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert getRemainder(5,4)==1, \"getRemainder function not working\"" @@ -305,9 +533,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert power(3,2)==9, \"power function not working\""