Python MCQ’s on Modules: SET 4

31. What is x if x = math.isfinite(float(‘0.0’))?

a) True

b) False

c) None

d) error

Check Answer

 

Answer: a
float(‘0.0’) is a finite number.

 

 

32. What will be the output of the following Python code?

>>> -float(‘inf’) + float(‘inf’)

a) inf

b) nan

c) 0

d) 0.0

Check Answer

Answer: b
The result of float(‘inf’)-float(‘inf’) is undefined.

 

33. What will be the output of the following Python code?

print(math.isinf(float(‘-inf’)))

a) error, the minus sign shouldn’t have been inside the brackets

b) error, there is no function called isinf

c) True

d) False

Check Answer

Answer: c
-float(‘inf’) is the same as float(‘-inf’).

 

34. What is the value of x if x = math.ldexp(0.5, 1)?

a) 1

b) 2.0

c) 0.5

d) none of the mentioned

Check Answer

Answer: d
The value returned by ldexp(x, y) is x * (2 ** y). In the current case x is 1.0.

 

35. What is returned by math.modf(1.0)?

a) (0.0, 1.0)

b) (1.0, 0.0)

c) (0.5, 1)

d) (0.5, 1.0)

Check Answer

Answer: a
The first element is the fractional part and the second element is the integral part of the argument.

 

 

 

36. What is the result of math.trunc(3.1)?

a) 3.0

b) 3

c) 0.1

d) 1

Check Answer

Answer: b
The integral part of the floating point number is returned.

 

37. What is the output of print(math.trunc(‘3.1’))?

a) 3

b) 3.0

c) error

d) none of the mentioned

Check Answer

Answer: c
TypeError, a string does not have __trunc__ method.

 

38. Which of the following is the same as math.exp(p)?

a) e ** p

b) math.e ** p

c) p ** e

d) p ** math.e

Check Answer

Answer: b
math.e is the constant defined in the math module.

 

39. What is returned by math.expm1(p)?

a) (math.e ** p) – 1

b) math.e ** (p – 1)

c) error

d) none of the mentioned

Check Answer

Answer: a
One is subtracted from the result of math.exp(p) and returned.

 

40. What is the default base used when math.log(x) is found?

a) e

b) 10

c) 2

d) none of the mentioned

Check Answer

Answer: a
The natural log of x is returned by default.

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

Leave a Comment