Page 246 - Computer Science Class 11 Without Functions
P. 246
Write a function call that would yield value of π rounded to three decimal places. What value will the
function call yield?
Even though importing all the functions of a module ( using from <module> import *) appears to be simple, it
is not usually wise to import all the functions of a module as some of the function names may conflict with the names
of data objects or functions defined by the programmer. So, if we are only interested in sqrt() and pow() functions,
we would prefer to write:
>>> from math import sqrt, pow
Some commonly used built-in functions of math module are described below:
1. math.ceil(num)
Function ceil() takes an integer or floating-point number as the input and returns the least integer greater than
or equal to the argument. For instance, the following function call returns the smallest integer greater than or
equal to 13.3.
>>> math.ceil(13.3)
14
>>> math.ceil(-13.3)
-13
Note that in the second example, since -14 < -13.3 < -13, thus, the smallest integer greater than -13.3 is -13.
What value will the function calls math.ceil(-1.6), math.ceil(-1), math.ceil(12.99),
math.ceil(0.86)return?
2. math.floor(num)
Function floor() takes an integer or floating-point number as the input and returns the largest integer smaller
than or equal to the argument. For instance, the following function call returns the largest integer smaller than or
equal to 13.3.
>>> math.floor(13.3)
13
>>> math.floor(-15.4)
-16
Note that in the second example, since -16<-15.4<-15, thus, the largest integer smaller than or equal to -15.4
is -16.
What value will the function calls math.floor(-1.6), math.floor(-1), math.floor(12.99),
math.floor(0.36)return?
3. math.sqrt(num)
Function sqrt() takes a positive integer or floating point number as the input and returns the square root of the
number. For instance, the following function call returns the square root of 25.
>>> 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
244 Touchpad Computer Science-XI

