Page 297 - Computer Science Class 11 With Functions
P. 297
2. Assertion(A): A Python module typically provides several functions to perform operations on data.
Reasoning(R): Once a module is imported, we can use all the functions defined in the module by the preceding function
name by the name of the module and a dot(.) operator.
3. Assertion(A): The statement, sqrt(25) may not lead to error.
Reasoning(R): The function sqrt() can be used without preceding it with module name math that contains it, if it has
been imported using a statement like:
from math import sqrt
Ans. 1. c 2. b 3. a
Case Based Questions
1. Lawrence wants to implement Heron's formula to calculate the area of a triangle. He wants to create a Python program
that accepts three sides of a triangle as an input, and then calculates and displays the area using Heron's formula as given
below:
s = (side1+side2+side3)/2
Area = square root (s(s-side1)(s-side2)(s-side3))
Ans. import math
def areaHeron(side1, side2, side3):
'''
Objective: To compute the area of a triangle using Heron's formula
Input Parameters: side1, side2, side3 - numeric value
Return Value: area - numeric value
'''
s = (side1+side2+side3)/2
area = math.sqrt(s*(s-side1)*(s-side2)*(s-side3))
return area
side1 = int(input('Enter length of side 1 : '))
side2 = int(input('Enter length of side 2 : '))
side3 = int(input('Enter length of side 3 : '))
area = areaHeron(side1, side2, side3)
print('The area of triangle is ', area)
2. Stuti has studied math module in class today. Her teacher has asked her to write a menu driven program to accept an angle
in degrees as an input, convert it to radians and then display sine, cosine and tangent of the angle using the functions from
math module. Help her complete the task.
Ans. import math
def trigo(angleDegree):
'''
Objective: To print sine, cosine, and tangent of the angree in degrees
Input Parameters: angle - numeric value
Return Value: None
'''
angleRadian = angleDegree * (math.pi/180)
print('The angle in radians is ', angleRadian)
print('The sine of angle ', angleDegree, ' degrees is ', math.sin(angleRadian ))
print('The cosine of angle ', angleDegree, ' degrees is ', math.cos(angleRadian ))
Modules 295

