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
151 changes: 94 additions & 57 deletions Functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"#this function adds two numbers passed as parameters\n",
Expand All @@ -101,36 +99,80 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"9"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"add(4,5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"-11"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"add(-6,-5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"14.6"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"add(5.6, 9)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'helloworld'"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"add (\"hello\", \"world\") # ooops this is weird!!"
]
Expand Down Expand Up @@ -169,19 +211,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"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"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"assert 2 + 2 == 4, \"Houston we've got a problem\" #this won't give an error!"
Expand All @@ -208,23 +248,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"# subtract function \n",
"\n",
"def subtract(n1,n2):\n",
" a1 = n1 - n2\n",
" return a1\n",
"# floorDivide function\n",
"\n",
"def floorDivide(n1,n2):\n",
" a1 = n1 // n2\n",
" return a1\n",
"# divide function\n",
"\n",
"def divide(n1,n2):\n",
" a1 = n1 / n2\n",
" return a1\n",
"# multiply function\n",
"\n",
"def multiply(n1,n2):\n",
" a1 = n1 * n2\n",
" return a1\n",
"# getRemainder function\n",
"\n",
"# power function"
"def getRemainder(n1,n2):\n",
" a1 = n1 % n2\n",
" return a1\n",
"# power function\n",
"def power(n1,n2):\n",
" a1 = n1 ** n2\n",
" return a1"
]
},
{
Expand All @@ -238,76 +289,62 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"assert add(4,5)==9, \"add function not working\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"assert subtract(4,5)==-1, \"subtract function not working\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"assert multiply(4,5)==20, \"multiply function not working\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"assert divide(5,5)==1.0, \"divide function not working\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"assert floorDivide(1,2)==0.5, \"floor divide function not working\""
"assert floorDivide(1,2)==0, \"loor divide function not working\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"assert getRemainder(5,4)==1, \"getRemainder function not working\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"assert power(3,2)==9, \"power function not working\""
Expand Down