Page 283 - Computer Science Class 11 With Functions
P. 283
>>> math.sqrt(25)
5.0
4. math.pow(num1, num2)
Function pow() takes two integers or floating point numbers as the input and returns the num1 raised to the
3
power of num2. For instance, the following function call computes 2 .
>>> math.pow(2, 3)
8.0
5. math.factorial(num)
Function factorial() takes a positive integer as an input and returns the factorial of the number. For instance,
the following function call returns the factorial of the number 5.
>>> math.factorial(5)
120
6. math.gcd(num1, num2)
Function gcd() takes two integers as an input and returns the greatest common divisor of num1 and num2.
For instance, the following function call returns 8 as the greatest common divisor of 16 and 24, both being divisible
by 8.
>>> math.gcd(16,24)
8
7. math.sin(num)
Function sin() takes a positive integer or floating point number in radians as an input and returns its arc sine
value. For instance, the following function call returns the sine value of pi/2 (3.14/2 in radians) as the output:
>>> math.sin(math.pi/2)
1.0
8. math.cos(num)
Function cos() takes a positive integer or floating point number in radians as an input and returns its cosine
value. For instance, the following function call returns the cosine value of 1.0 (radians) as the output:
>>> math.cos(0.0)
1.0
Give the function call that would yield cosine of an angle of 60°? Recall that π radians = 180°.
9. math.tan(num)
Function tan() takes a positive integer or floating point number in radians as an input and returns its arc tan
value. For instance, the following function call returns the tangent value of pi/4 (radians) as the output:
>>> math.tan(math.pi/4)
0.9999999999999999
11.1.1 random Module
Python module random is another useful module that enables us to generate random numbers. The random()
function of the random module enables us to generate a random number between 0 and 1.
>>> import random
>>> help(random.random)
Help on built-in function random:
random() method of random.Random instance
random() -> x in the interval [0, 1).
>>> random.random()
0.4988834047541426
Modules 281

