Attributes of random module:
random module is used to generate random numbers, which are used to generate captcha code, in
computer games like throwing of a dice, picking a number or flipping a coin, shuffling cards,
creating lottery scratch cards.
1. random()
Syntax: [Link]()
random() method generates a random number from 0 to 1. It does not takes any parameter and
returns floating point values between 0 and 1
>>> import random as r
>>> [Link]()
0.13939737870230484
2. randint()
Syntax: [Link](a, b)
randint() method accepts two parameters and returns a random integer number between a and b
(both a and b are inclusive)..
>>> import random as r
>>> [Link](4,9)
4
>>> [Link](4,9)
7
3. randrange()
Syntax: [Link](start, stop, step)
randrange() method generates a random integer number between start and stop, where start is
inclusive and stop is exclusive. The default value of start is 0 and step is 1.
>>> import random as r
#Generate any random number between 4 to 9 (4 include, but 9
exclude)
>>> [Link](4,9)
5
#Generate any even random number between 3 to 9 (3 include, but
9 exclude)
>>>[Link](3,9,2)
4
Attributes of statistics module
The statistics module implements many statistical methods like mean(), median() and mode etc.
To use statistical methods we need to import the statistics module.
import statistics as s
1. mean()
Syntax: [Link](data)
The mean() method returns the arithmetic mean (average) of the given data set.
2. median()
Syntax: [Link](data)
The mean() method calculates the median (middle value) of the given data set. This method also
sorts the data in ascending order before calculating the median.
Note: If the number of data values is odd, it returns the exact middle value. If the number of data
values is even, it returns the average of the two middle values.
3. mode()
Syntax: [Link](data)
The mean() method calculates the mode (central tendency) of the
given data set. import statistics as s
L = [1, 4, 5, 7, 4, 7, 4, 10, 12]
print("Mean of the data Set: ", [Link](L))
print("Median of the data Set: ", [Link](L))
print("Mode of the data Set: ", [Link](L))
Output:
Mean of the data Set: 6
Median of the data Set: 5
Mode of the data Set: 4