Page 288 - Computer Science Class 11 With Functions
P. 288
For this purpose, we need to import these functions from the module geometry as follows:
import sys
sys.path.append('D:\classXII\ch1')
from geometry import areaTriangle, areaRectangle
Next, we demonstrate how the module geometry may be used from the Python shell:
>>> import sys
>>> sys.path.append('D:\classXII\ch2')
>>> from geometry import areaTriangle, areaRectangle
>>> areaTriangle(5, 6)
15.0
>>> areaRectangle(5, 6)
30
Let's Summarise
Ø Some commonly used built-in functions from the math module are illustrated in the following table:
S. Function Description of Return Value(s) Examples
No. Argument(s)
1 math.ceil(num) Integer or Ceiling (highest closest >>> math.ceil(13.3)
floating point integer) value of num 14
number >>> math.ceil(-15.4)
-15
-16<-15.4<=-15
2 math.floor(num) Integer or Floor(lowest closest >>> math.floor(13.3)
floating point integer) value of num 13
number >>> math.floor(-15.4)
-16
3 math.fabs(num) Integer or Absolute value of num >>> math.fabs(-14.7)
floating point (returns floating 14.7
number point number as
>>> math.fabs(62.1)
the absolute
62.1
value)
4 math. Positive integer Factorial of num >>> math.factorial(5)
factorial(num) 120
5 math. Integer or num1%num2 >>> math.fmod(19,3)
fmod(num1,num2) floating point (sign of num1) 1.0
numbers
6 math. Integers Greatest common >>> math.gcd(56,78)
gcd(num1,num2) divisor of num1 and 2
num2 >>> math.gcd(-10,4)
2
7 math. Integers or num1 num2 >>> math.pow(14,3)
pow(num1,num2) floating point num1 raised to the 2744.0
numbers power of num2 >>> math.pow(-4,2)
16.0
286 Touchpad Computer Science-XI

