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
182 changes: 136 additions & 46 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": 3,
"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": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"9"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"add(4,5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"-11"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"add(-6,-5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"14.6"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"add(5.6, 9)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'helloworld'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"add (\"hello\", \"world\") # ooops this is weird!!"
]
Expand Down Expand Up @@ -169,19 +211,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"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<ipython-input-8-3b9b6d7c52e5>\u001b[0m in \u001b[0;36m<module>\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
},
"metadata": {},
"outputs": [],
"source": [
"assert 2 + 2 == 4, \"Houston we've got a problem\" #this won't give an error!"
Expand All @@ -208,23 +260,75 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2\n",
"2.0\n",
"21\n",
"0\n",
"184528125\n"
]
}
],
"source": [
"# subtract function \n",
"def add (num,num1):\n",
" ans = num+num1\n",
" return ans\n",
"\n",
"\n",
"\n",
"# floorDivide function\n",
"\n",
"def subtract (num,num1):\n",
" ans = num-num1\n",
" return ans\n",
" \n",
"print(subtract(7, 5))\n",
"# floorDivide function\n",
"def floorDivide (num,num1):\n",
" ans = num//num1\n",
" return ans\n",
" \n",
"floorDivide(11,5)\n",
"# divide function\n",
"def divide (num,num1):\n",
" ans = num / num1\n",
" return ans \n",
"\n",
"print(divide(14,7))\n",
"\n",
"# multiply function\n",
"def multiply(num,num1):\n",
" ans = num*num1\n",
" return ans\n",
" \n",
"print(multiply(3,7))\n",
"\n",
"# getRemainder function\n",
"def getRemainder(num,num1):\n",
" ans = num%num1\n",
" return ans\n",
" \n",
"print(getRemainder(25,5))\n",
"\n",
"# power function"
"# power function\n",
"def power(num,num1):\n",
" ans = num**num1\n",
" return ans\n",
" \n",
"print(power(45,5))\n",
"\n",
"assert add(4,5)==9, \"add function not working\"\n",
"assert subtract(4,5)==-1, \"subtract function not working\"\n",
"assert multiply(4,5)==20, \"multiply function not working\"\n",
"assert divide(5,5)==1.0, \"divide function not working\"\n",
"assert floorDivide(1,2)==0, \"floor divide function not working\"\n",
"assert getRemainder(5,4)==1, \"getRemainder function not working\"\n",
"assert power(3,2)==9, \"power function not working\"\n"
]
},
{
Expand All @@ -239,9 +343,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 +352,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 +361,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 +370,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 +379,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 +388,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 +397,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"assert power(3,2)==9, \"power function not working\""
Expand Down