Page 292 - Computer Science Class 11 With Functions
P. 292
i. Mean height of five boys given 150,154, 160, 161, and 165 cm as their heights respectively.
j. Factorial of the number 10.
Ans. a. random.randrange(1,101,2)
b. round(math.pi,2)
c. math.log(100,2)
d. math.log(100,10)
e. math.log(100,math.e)
f. math.sin(math.pi/4)
g. math.tan(2*math.pi)
h. math.gcd(18, 34)
i. statistics.mean( [150, 154, 160, 161, 165] )
j. math.factorial(10)
3. Give all possible outputs that may be produced when the following code is executed.
import random
continents = ['Asia', 'Australia', 'South America', 'North America', 'Europe', 'Antarctica']
option1 = random.randint(2, 4)
option2 = random.randint(3, 5)
for x in range(option1, option2):
print(continents[x], end = '#')
Ans. Europe#
North America#Europe#
North America#
South America#
South America#North America#Europe#
South America#North America#
4. What will be the output of the given code?
def calculate(var1,var2=2, var3=0):
total=var1+var2+var3
print(total)
calculate(4)
Ans. 6
Solved Programming Questions
1. Write a function max3(n1, n2, n3) that finds the maximum out of three numbers n1, n2, and n3.
Ans. def max3(n1, n2, n3):
'''
Objective: To find maximum of three numbers
Input Parameters: n1, n2, n3 - numeric values
Return Value: maximum of n1, n2, n3 - numeric value
'''
'''
Approach:
Compare each number with the other two numbers. Assign the maximum to the maximum
among n1, n2, and n3.
290 Touchpad Computer Science-XI

