From 07a6ad1cf755022333aaa867a340754187da91a6 Mon Sep 17 00:00:00 2001 From: "joshua.brown" Date: Tue, 26 Sep 2017 13:55:03 +0000 Subject: [PATCH 1/4] Done --- Functions.ipynb | 240 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 191 insertions(+), 49 deletions(-) diff --git a/Functions.ipynb b/Functions.ipynb index df58b4c..810e64f 100644 --- a/Functions.ipynb +++ b/Functions.ipynb @@ -67,6 +67,96 @@ "\n" ] }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n", + "10\n" + ] + } + ], + "source": [ + "#Answers\n", + "\n", + "#1.\n", + "\n", + "answer = 2 + 6\n", + "print(answer)\n", + "\n", + "#2.\n", + "\n", + "difference = abs(15-25)\n", + "print(difference)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.05223880597014925\n" + ] + } + ], + "source": [ + "#3.\n", + "\n", + "divmod(50, 26)\n", + "\n", + "\n", + "#4.\n", + "decimal = 7 / float(134)\n", + "print(decimal)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "50\n" + ] + } + ], + "source": [ + "#5.\n", + "answer2 = 5*10\n", + "print(answer2)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + } + ], + "source": [ + "#6.\n", + "remainder = 32 % 5\n", + "print(remainder)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -78,10 +168,8 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 5, + "metadata": {}, "outputs": [], "source": [ "#this function adds two numbers passed as parameters\n", @@ -101,36 +189,80 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "add(4,5)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "-11" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "add(-6,-5)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "14.6" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "add(5.6, 9)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'helloworld'" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "add (\"hello\", \"world\") # ooops this is weird!!" ] @@ -169,19 +301,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "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" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 12, + "metadata": {}, "outputs": [], "source": [ "assert 2 + 2 == 4, \"Houston we've got a problem\" #this won't give an error!" @@ -209,22 +351,36 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ - "# subtract function \n", "\n", - "# floorDivide function\n", - "\n", - "# divide function\n", + "#subtract function \n", + "def subtract (number1, number2):\n", + " answer = number1-number2\n", + " return answer\n", + "#floorDivide function\n", + "def floorDivide (number1, number2):\n", + " answer = number1//number2\n", + " return answer\n", + "#divide function\n", + "def divideAnswer = number1/number2\n", + " return answer\n", "\n", "# multiply function\n", - "\n", + "return answer\n", + "def multiply (number1, number2):\n", + " answer = number1*number2\n", + " \n", "# getRemainder function\n", + "def getRemainder (number1, number2):\n", + " answer = number1%number2\n", + " return answer\n", "\n", - "# power function" + "#power function\n", + "def power (number1, number2):\n", + " answer = number1**number2\n", + " return answer" ] }, { @@ -239,9 +395,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert add(4,5)==9, \"add function not working\"" @@ -250,9 +404,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert subtract(4,5)==-1, \"subtract function not working\"" @@ -261,9 +413,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert multiply(4,5)==20, \"multiply function not working\"" @@ -272,9 +422,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert divide(5,5)==1.0, \"divide function not working\"" @@ -283,20 +431,16 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "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 - }, + "metadata": {}, "outputs": [], "source": [ "assert getRemainder(5,4)==1, \"getRemainder function not working\"" @@ -305,9 +449,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "assert power(3,2)==9, \"power function not working\"" From dbcf240fa62e58a728076532fe9f33fb9b5ca2ac Mon Sep 17 00:00:00 2001 From: Joshua Brown <31473980+JoshuaRDBrown@users.noreply.github.com> Date: Thu, 28 Sep 2017 11:15:29 +0100 Subject: [PATCH 2/4] Fix code and complete notebook --- Functions.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Functions.ipynb b/Functions.ipynb index 810e64f..044375d 100644 --- a/Functions.ipynb +++ b/Functions.ipynb @@ -284,7 +284,7 @@ "\n", "Here is a simple example;\n", "```python\n", - "assert 2 + 2 == 5, \"Houston we've got a problem\"\n", + "assert 2 + 2 == 4, \"Houston we've got a problem\"\n", "```\n", "\n", "Since 2+2 doed **NOT** equal 5, this code will print out the message \"Houston we've got a problem\" - you can test it out below\n", From abcbf402f9c89f3f6cb629a441e6df96c2e95b03 Mon Sep 17 00:00:00 2001 From: Joshua Brown <31473980+JoshuaRDBrown@users.noreply.github.com> Date: Thu, 28 Sep 2017 11:16:55 +0100 Subject: [PATCH 3/4] Complete notebook + fix errors --- Functions.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Functions.ipynb b/Functions.ipynb index 044375d..f5ca4ab 100644 --- a/Functions.ipynb +++ b/Functions.ipynb @@ -284,7 +284,7 @@ "\n", "Here is a simple example;\n", "```python\n", - "assert 2 + 2 == 4, \"Houston we've got a problem\"\n", + "assert 2 + 2 == 5, \"Houston we've got a problem\"\n", "```\n", "\n", "Since 2+2 doed **NOT** equal 5, this code will print out the message \"Houston we've got a problem\" - you can test it out below\n", @@ -317,7 +317,7 @@ } ], "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" ] }, { From 30e8df87c2d56fc3122be4e7f85e59150c9f96c3 Mon Sep 17 00:00:00 2001 From: Joshua Brown <31473980+JoshuaRDBrown@users.noreply.github.com> Date: Thu, 28 Sep 2017 11:18:07 +0100 Subject: [PATCH 4/4] Complete notebook + fix errors --- Functions.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Functions.ipynb b/Functions.ipynb index f5ca4ab..810e64f 100644 --- a/Functions.ipynb +++ b/Functions.ipynb @@ -317,7 +317,7 @@ } ], "source": [ - "assert 2 + 2 == 4, \"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\n" ] }, {