Create and import custom module in python

Create and import custom module in python:

  • If create a custom module to import this module in another module, it should have function definition only.
  • File inclusion must be import keyword with the name of the created custom module.

Save the program as a calculation.c

  1. def sqr(n):

        return n*n

    def cube(n):

        return n*n*n

Created another program Example.py for file inclusion:

  1. import calculation

    x=int(input("Enter a value to find square value:"))

    print("%d square value is:%d"%(x,calculation.sqr(x)))

    y=int(input("Enter a value to find cube value:"))

    print("%d cube value is:%d"%(y,calculation.cube(y)))

Output:

Share:

No comments:

Post a Comment

Popular Posts

Search This Blog

Powered by Blogger.

Service Support

Need our help to Learn or Post New Concepts Contact me

Recent Posts

Service Support

Need our help to Learn or Post New Concepts Contact me