Python Module PDF
Python Module PDF
MODULES
VARIABLES OTHER
PYTHON
MODULES
FUNCTIONS
VARIABLES
IMPORT
CLASSES
MEMBERS
OTHER
METHODS PYTHON
MODULES
Importing Python modules
To import entire module
◼ import <module name>
◼ Example: import math
🞑 Statistical module
Math module
This module provides variousfunction to
perform arithmetic operations.
Example of functions in math modules are:
sqrt ceil floor pow
fabs sin cos tan
Example of variablesin math modules are:
🞑 pi
🞑 e
Math module functions
sqrt(x) : this function returns the square root of
number(x). module name is
required before
function name here
Output is lessthan 1
random() function
Togenerate random number between given range
of values using random(), the following format
should be used:
🞑 Lower_range + random() * (upper_range-lower_range)
🞑 For example to generate number between 10 to 50:
◼ 10 + random() * (40)
randint() function
Another way to generate random number is
randint() function, but it generate integer numbers.
Both the given range values are inclusive i.e. if
we generate randomnumber as :
🞑 randint(20,70)
◼ In above example random numberbetween 20 to 70 will
be taken. (including 20 and 70 also)
E
X
A
M
P
L
E
O
U
T
P
U
T
Just a Minute…
Give the following python code, whichisrepeated
four times. What could be the possible set of
output(s) out of four sets (ddd is any combination of
digits)
import random
print(15 + random.random()*5)
a) b) c) d)
17.ddd 15.ddd 14.ddd 15.ddd
19.ddd 17.ddd 16.ddd 15.ddd
20.ddd 19.ddd 18.ddd 15.ddd
15.ddd 18.ddd 20.ddd 15.ddd
Just a Minute…
What could be the minimumpossible and maximum
possible numbers by following code
import random
print(random.randint(3,10)-3)
In a school fest, three randomly chosen students out
of 100 students (having roll number 1 -100) have to
present the bouquet to the guests. Help the school
authorities choose three students randomly
Just a Minute…
Just a Minute…
Look at the following Python code and find the possible output(s) from the
options (i) to (iv) following it. Also, write the maximum and the minimum values
that can be assigned to the variable PICKER.
Note:
‐ Assumeall the required header files are already being included in the code.
‐ The function randint()generates an integer between 1 to n
import random
PICKER=1+random.randint(0,2)
COLOR=[”BLUE”,”PINK”,”GREEN”,”RED”]
for I in range(1,PICKER+1):
for j in range(I+1):
print(COLOR[j],end=‘’)
print()
What are the possible outcome(s) executed from the following
code? Also specify the maximum and minimum values that
can be assigned to variable PICK
1) 2)
DELHIDELHI DELHI
MUMBAIMUMBAI DELHIMUMBAI
CHENNAICHENNAI DELHIMUMBAICHEN
KOLKATAKOLKA NAI
TA
3) 4)
DELHI DELHI
MUMBAI DELHIMUMBAI
CHENNAI KOLKATAKOLKATAKOLKATA
KOKLATA
randrange() function
This function is also used to generate
random number within given range.
Syntax
🞑 randrange(start,stop,step)
It will generate random
number between 5 to 14
It will generate
random number
between 1 to 29 with
stepping of 2 i.e. it
will generate number
with gap of 2 i.e.
1,3,5,7 and so on
Mathematics Game for Kids
Mathematics Game for Kids
Statistical Module
This module provides functions for calculating
mathematical statistics of numeric (Real-valued)
data.
We will deal with 3 basic function under this module
🞑 Mean
🞑 Median
🞑 mode
Mean
The mean isthe average of all numbers and is
sometimes called the arithmeticmean.
Here, 10 occurs
mostin the list.