0% found this document useful (0 votes)
4 views

random

The document provides an overview of Python's standard library modules, specifically focusing on the math, random, and statistics modules. It includes examples of various functions within these modules, such as mathematical operations and generating random numbers. Additionally, it highlights the usage of functions like mean, median, and mode from the statistics module.

Uploaded by

Ishaan Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

random

The document provides an overview of Python's standard library modules, specifically focusing on the math, random, and statistics modules. It includes examples of various functions within these modules, such as mathematical operations and generating random numbers. Additionally, it highlights the usage of functions like mean, median, and mode from the statistics module.

Uploaded by

Ishaan Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

Random()

Working with standard library modules

math random statistics

Other than few built-in functions(e.g. pow, len….), python’s


standard libraries also provide some modules (e.g. math,
random, statistics, …) having functionality for specialized actions.
Math module
Math module
Math module
>>> from math import * >>> pi
>>> ceil(3.4) 3.141592653589793
4 >>> sqrt(81)
>>> ceil(-3.4) 9.0
-3 >>> sqrt(81.0)
>>> floor(2.5) 9.0
2 >>> sqrt(-81)
>>> floor(-2.5) Traceback (most recent call
-3 last):
>>> exp(2) File "<pyshell#10>", line 1, in
7.38905609893065 <module>
>>> exp(-2) sqrt(-81)
0.1353352832366127 ValueError: math domain error
>>> pow(5,2) >>> fabs(-3)
25.0 3.0
>>> pow(-5,2) >>> fabs(-3.5)
25.0 3.5
>>> pow(5,-2) >>> fabs(3)
0.04 3.0
>>> pow(5.5,2) >>> sin(30)
30.25 -0.9880316240928618
>>> pow(5.5,2.3) >>> sin(radians(30))
50.44686540422945 0.49999999999999994
Math module
TASK:Math module
Math module
statistics module

mean median mode


statistics module
statistics module
random module

random() randint(a,b)

randrange(<start>,<stop>,<value>)
random()

Between 0 to 1(1
1
exclusive)

Between user
defined range
(upper exclusive)
randint(a,b)

Between 15 and 35
1
(both inclusive)

Can’t interchange
the upper and
lower limit
randrange(<start>,<stop>,<step>)
It returns random numbers from range start ….stop with step value

Note: usage of from


statement(random.
Not required)
TASK
TASK

You might also like