Modules and Packages (24!12!2022)
Modules and Packages (24!12!2022)
Modules and Packages (24!12!2022)
Types of Modules
In [ ]: Two Types of Modules:
Builtin Modules -->That modules which we can directly use by importing it. There is no need
to define that module.Internally Pvm knows the variables/functions/classes that are present in
that module.
Example:
math module
random module
User Defined Modules --> that modules which are prepared by the developer as per the
business requirement.
Example:
addf
subt
Syntax:
import Module_Name
Help Function
In [ ]: Help is a function that is used to give the description of a module
Math Module
In [15]: import math
#print(help(math))
print(math.sqrt(144)) #math.sqrt() is used to return square root of a number
print(math.factorial(5)) #math.factorial() is used to return the factorial of a number
print(math.sin(200))
print(math.tanh(200))
print(math.pi) #math.pi is used to return the pi value
print(math.ceil(5.4)) #math.ceil() is used to return the ceil value
print(math.floor(6.5)) #math.floor() is used to return the floor value
12.0
120
-0.8732972972139946
1.0
3.141592653589793
6
6
Random Module
In [ ]: In Random Module Three Functions are Very Important:
1.random.random()
2.random.randint()
3.random.uniform()
random.random() Function
In [ ]: random.random() --> Function is used to generate a random number from 0 to 1
0.8416114160074224
0.8294094026760904
0.7685731903672596
0.21528987083822326
0.49567720618502364
0.5204319481599796
0.504787493191886
0.014157233756902698
0.34142647030943163
0.7745919869020532
random.randint()
In [ ]: random.randint(start,end) --> Function is used to return a random number between a given range.
--> It is always expecting Two Arguments(start and end)
61
138
20
12
149
1367
6619
4028
8524
7026
In [44]: x=random.randint(999,9999)
print(x)
y=int(input("Enter OTP"))
if x==y:
print("Successfully Logged In")
else:
print("Invalid OTP")
8180
Enter OTP99909
Invalid OTP
random.uniform() Function
In [ ]: random.uniform(start,end) --> Function is used to return a random floating number between a given
range.
--> It is always expecting two arguments to be passed(start,end)
In [3]: #uniform function --> return random number within a given range(floating number)
for i in range(10):
print(random.uniform(1,200))
70.01275628183346
144.11944035004856
184.36375642622662
48.615149521991526
31.0108295962854
101.71892255984008
153.53749459066776
25.38816577813439
155.46502401635854
53.661418316957594
Example:
In [52]: import info
print(help(info))
print(info.college_name)
print(info.Calculater_info(20,40))
print(info.wish())
NAME
info
FUNCTIONS
Calculater_info(x, y)
wish()
DATA
college_name = 'Edyoda Digital university'
FILE
c:\users\praty\info.py
None
Edyoda Digital university
Addition is 60
Subtraction is -20
Division is 0
Modulus is 20
Exponent is 10995116277760000000000000000000000000000000000000000
NAME
info
FUNCTIONS
Calculater_info(x, y)
welcome(name, Batch)
wish()
DATA
Batch = 'DS290922A'
college_name = 'Edyoda Digital university'
name = 'Jappan Singh Anand'
FILE
c:\users\praty\info.py
None
Edyoda Digital university
Addition is 60
Subtraction is -20
Division is 0
Modulus is 20
Exponent is 10995116277760000000000000000000000000000000000000000
Example:
In [67]: import Python.info
print(Python.info.college_name)
print(Python.info.Calculater_info(10,20))
print(Python.info.wish())
Example
In [75]: from Python import *
print(info.college_name)
print(info.Calculater_info(10,20))
print(info.wish())
print(salary.Employee())
NAME
Python.info
FUNCTIONS
Calculater_info(x, y)
welcome(name, Batch)
wish()
DATA
Batch = 'DS290922A'
college_name = 'Edyoda Digital university'
name = 'Jappan Singh Anand'
FILE
c:\users\praty\python\info.py
None
Edyoda Digital university
Addition is 60
Subtraction is -20
Division is 0
Modulus is 20
Exponent is 10995116277760000000000000000000000000000000000000000
Hello
None
World
None
In [ ]: