From 0231c422f20545833eb66a760aea05ca8c2df590 Mon Sep 17 00:00:00 2001 From: "abby.debell@ada.ac.uk" Date: Tue, 26 Sep 2017 13:13:45 +0000 Subject: [PATCH 1/2] Functions --- Functions.ipynb | 170 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 119 insertions(+), 51 deletions(-) diff --git a/Functions.ipynb b/Functions.ipynb index df58b4c..137f926 100644 --- a/Functions.ipynb +++ b/Functions.ipynb @@ -78,10 +78,8 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 1, + "metadata": {}, "outputs": [], "source": [ "#this function adds two numbers passed as parameters\n", @@ -101,36 +99,80 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "add(4,5)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "-11" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "add(-6,-5)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "14.6" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "add(5.6, 9)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'helloworld'" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "add (\"hello\", \"world\") # ooops this is weird!!" ] @@ -169,9 +211,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "AssertionError", + "evalue": "Houston we've got a problem", + "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[0;32m----> 1\u001b[0;31m \u001b[0;32massert\u001b[0m \u001b[0;36m2\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m2\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m5\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"Houston we've got a problem\"\u001b[0m \u001b[0;31m#This will give an AssertionError\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mAssertionError\u001b[0m: Houston we've got a problem" + ] + } + ], "source": [ "assert 2 + 2 == 5, \"Houston we've got a problem\" #This will give an AssertionError\n" ] @@ -179,9 +233,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!" @@ -208,23 +260,39 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 22, + "metadata": {}, "outputs": [], "source": [ "# subtract function \n", + "def subtract(n1,n2):\n", + " a1 = n1 - n2\n", + " return a1\n", "\n", "# floorDivide function\n", + "def floorDivide(n1,n2):\n", + " a1 = n1 // n2\n", + " return a1\n", "\n", "# divide function\n", + "def divide(n1,n2):\n", + " a1 = n1 / n2\n", + " return a1\n", "\n", "# multiply function\n", + "def multiply(n1,n2):\n", + " a1 = n1 * n2\n", + " return a1\n", "\n", "# getRemainder function\n", - "\n", - "# power function" + "def getRemainder(n1,n2):\n", + " a1 = n1 % n2\n", + " return a1\n", + "\n", + "# power function\n", + "def power(n1,n2):\n", + " a1 = n1 ** n2\n", + " return a1" ] }, { @@ -238,10 +306,8 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 15, + "metadata": {}, "outputs": [], "source": [ "assert add(4,5)==9, \"add function not working\"" @@ -249,10 +315,8 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 23, + "metadata": {}, "outputs": [], "source": [ "assert subtract(4,5)==-1, \"subtract function not working\"" @@ -260,10 +324,8 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 17, + "metadata": {}, "outputs": [], "source": [ "assert multiply(4,5)==20, \"multiply function not working\"" @@ -271,10 +333,8 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 18, + "metadata": {}, "outputs": [], "source": [ "assert divide(5,5)==1.0, \"divide function not working\"" @@ -282,21 +342,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 25, + "metadata": {}, "outputs": [], "source": [ - "assert floorDivide(1,2)==0.5, \"floor divide function not working\"" + "assert floorDivide(1,2)==0, \"floor divide function not working\"" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 20, + "metadata": {}, "outputs": [], "source": [ "assert getRemainder(5,4)==1, \"getRemainder function not working\"" @@ -305,13 +361,25 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert power(3,2)==9, \"power function not working\"" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { From 75e1a9be0e1a0e8a02c7af7e1d2b1f4d020f0ceb Mon Sep 17 00:00:00 2001 From: "abby.debell@ada.ac.uk" Date: Mon, 2 Oct 2017 12:23:02 +0000 Subject: [PATCH 2/2] write the functions assignment --- Functions.ipynb | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/Functions.ipynb b/Functions.ipynb index 137f926..7cdfa8a 100644 --- a/Functions.ipynb +++ b/Functions.ipynb @@ -211,23 +211,11 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 1, "metadata": {}, - "outputs": [ - { - "ename": "AssertionError", - "evalue": "Houston we've got a problem", - "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[0;32m----> 1\u001b[0;31m \u001b[0;32massert\u001b[0m \u001b[0;36m2\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m2\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m5\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"Houston we've got a problem\"\u001b[0m \u001b[0;31m#This will give an AssertionError\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mAssertionError\u001b[0m: Houston we've got a problem" - ] - } - ], + "outputs": [], "source": [ - "assert 2 + 2 == 5, \"Houston we've got a problem\" #This will give an AssertionError\n" + "assert 2 + 2 == 4, \"Houston we've got a problem\" #This will give an AssertionError\n" ] }, {