Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
288 changes: 257 additions & 31 deletions Functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand All @@ -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",
Expand Down Expand Up @@ -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": {},
Expand All @@ -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<ipython-input-19-ffba8c2c9178>\u001b[0m in \u001b[0;36m<module>\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<ipython-input-24-c34e4e7bcbea>\u001b[0m in \u001b[0;36m<module>\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<ipython-input-25-8b6577173b1f>\u001b[0m in \u001b[0;36m<module>\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",
Expand Down Expand Up @@ -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\""
Expand All @@ -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\""
Expand All @@ -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\""
Expand All @@ -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\""
Expand All @@ -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\""
Expand All @@ -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\""
Expand All @@ -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\""
Expand Down