Monday, March 8, 2021

Python Custom Module Create

 

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(n1n2):
    return n1 + n2

def sub(n1n2):
    return n1 - n2

def mult(n1n2):
    return n1 * n2

def div(n1n2):
    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) 

Sample Image:













No comments:

Post a Comment

How to Write Summary of a Research Paper

Paper Summary should contain the following points: What problem author’s solved? What are the motivations for that problem? Why is it import...