Computer Science
CLASS-XII (Code No. 083)
DPS RKP Computer Science Department
Revision of the basics of Python covered in Class XI
PART-5
2022-2023
Unit 1: Computational Thinking and Programming - 2
REVIEW PART-5
Revision of the basics of Python covered in Class XI.
● Introduction to Python modules: Importing math module (pi, e, sqrt, ceil,
floor, pow, fabs, sin, cos, tan); random module (random, randint, randrange),
statistics module (mean, median, mode).
DPS RKP Computer Science Department
2
math module
math Description
pi Value of pie
e Value of exponent
DPS RKP Computer Science Department
sqrt Returns square root
ceil Returns higher int
floor Returns lower int
pow Returns raised to power
fabs Returns absolute value (float)
sin Returns value of sine
cos Returns value of cosine
tan Returns value of tan
3
Differences between **, pow(), [Link]() 4
** pow() [Link]()
Operator builtin Belongs to math module
Returns integer result if Returns integer result if Always returns float
DPS RKP Computer Science Department
both operands are both parameters are result even if both
integers integers parameters are integers
N=pow(3,2,2)
Has third parameter also
and will have calculation
equivalent to the
following expression
N=(3**2)%2
Fastest Slowest
random module
random Syntax Description
random random() Returns float in between
0.0 and 1.0
DPS RKP Computer Science Department
randint randint(<Start>,<End>) Returns an integer in between
start value and end value
(including start and end values)
randrange randrange(<Start>,<End+1>,<Step>) Returns an integer between
start value and end value in
given step (1 by default - if not
Optional mentioned). To include End
(1 by default) value in this we need to write
End+1)
5
Statistics module
statistics
mean Returns mean of the collection
median Returns median of the collection
DPS RKP Computer Science Department
mode Returns mode of the collection
6
Happy Learning…
DPS RKP Computer Science Department
Thank you!
Department of Computer Science