Python MCQ’s on Modules: SET 3

21. What is the value returned by math.fact(6)?

a) 720

b) 6

c) [1, 2, 3, 6]

d) error

Check Answer

Answer: d
NameError, fact() is not defined.

 

 

22. What is the value of x if x = math.factorial(0)?

a) 0

b) 1

c) error

d) none of the mentioned

Check Answer

Answer: b
Factorial of 0 is 1.

 

23. What is math.factorial(4.0)?

a) 24

b) 1

c) error

d) none of the mentioned

Check Answer

Answer: a
The factorial of 4 is returned.

 

24. What will be the output of print(math.factorial(4.5))?

a) 24

b) 120

c) error

d) 24.0

Check Answer

Answer: c
Factorial is only defined for non-negative integers.

 

25. What is math.floor(0o10)?

a) 8

b) 10

c) 0

d) 9

Check Answer

Answer: a
0o10 is 8 and floor(8) is 8.

 

26. What does the function math.frexp(x) return?

a) a tuple containing the mantissa and the exponent of x

b) a list containing the mantissa and the exponent of x

c) a tuple containing the mantissa of x

d) a list containing the exponent of x

Check Answer

Answer: a
It returns a tuple with two elements. The first element is the mantissa and the second element is the exponent.

 

27. What is the result of math.fsum([.1 for i in range(20)])?

a) 2.0

b) 20

c) 2

d) 2.0000000000000004

Check Answer

Answer: a

The function fsum returns an accurate floating point sum of the elements of its argument.

 

28. What is the result of sum([.1 for i in range(20)])?

a) 2.0

b) 20

c) 2

d) 2.0000000000000004

Check Answer

Answer: d
There is some loss of accuracy when we use sum with floating point numbers. Hence the function fsum is preferable.

 

29. What is returned by math.isfinite(float(‘inf’))?

a) True

b) False

c) None

d) error

Check Answer

Answer: b
float(‘inf’) is not a finite number.

 

30. What is returned by math.isfinite(float(‘nan’))?

a) True

b) False

c) None

d) error

Check Answer

Answer: b
float(‘nan’) is not a finite number.

Page  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15      16 

Leave a Comment