Let's say we want to create our own module which have some functions like add, sub, mult, and div.
1st step:
Let's create arithmetic.ipynb file :
Code:
def add(n1, n2):
return n1 + n2
def sub(n1, n2):
return n1 - n2
def mult(n1, n2):
return n1 * n2
def div(n1, n2):
return n1 / n2
Sample Image:
2nd Step:
Now, download as a .py file ( arithmetic.py) . Then create test.ipynb file:
As Google Colab run in another virtual machine instead of google drive we need to upload the arithmetic.py file in to Colab. So in test.ipynb we will write:
Code:
from google.colab import files
files.upload()
Then , upload the arithmetic.py file.
3rd Step:
After uploading, import your custom module arithmetic and call the function add(). Give two input numbers and see the addition result.
Code:
import arithmetic as ar
ar.add(5,6)
No comments:
Post a Comment