Page 261 - Computer Science V2.0 Class 11
P. 261
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 ))
print('The tangent of angle ', angleDegree, ' degrees is ', math.tan(angleRadian ))
angleDegree = int(input('Enter angle in degrees '))
trigo(angleDegree)
Assessment
A. Multiple Choice questions.
1. Consider the given Python code.
import random
devices = ['Monitor', 'Keyboard', 'Mouse', 'Speaker']
for i in range(random.randint(0, 2)):
print(devices[i], '*', end=' ')
Which of the following lines of output will never be produced on execution of the above code?
a. Monitor * Keyboard *
b. Monitor*
c. Monitor * keyboard * Mouse *
d. None of these
2. Consider the program given below:
import random
values = [10, 30, 50, 70, 90, 110, 130]
fromVal = random.randint(1, 3)
to = random.randint(2, 4)
Modules 247

