Python MCQ’s on Modules: SET 5

41. Which of the following aren’t defined in the math module?

a) log2()

b) log10()

c) logx()

d) none of the mentioned

Check Answer

Answer: c
log2() and log10() are defined in the math module.

 

 

42. What is returned by int(math.pow(3, 2))?

a) 6

b) 9

c) error, third argument required

d) error, too many arguments

Check Answer

Answer: b
math.pow(a, b) returns a ** b.

 

43. What is output of print(math.pow(3, 2))?

a) 9

b) 9.0

c) None

d) None of the mentioned

Check Answer

Answer: b
math.pow() returns a floating point number.

 

44. What is the value of x if x = math.sqrt(4)?

a) 2

b) 2.0

c) (2, -2)

d) (2.0, -2.0)

Check Answer

Answer: b
The function returns one floating point number.

 

45. What does math.sqrt(X, Y) do?

a) calculate the Xth root of Y

b) calculate the Yth root of X

c) error

d) return a tuple with the square root of X and Y

Check Answer

Answer: c
The function takes only one argument.

 

 

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

 

import datetime

d=datetime.date(2016,7,24)

print(d)

a) Error

b) 2017-07-24

c) 2017-7-24

d) 24-7-2017

Check Answer

Answer: b
In the snippet of code shown above, we are simply printing the date entered by us. We enter the date in the format: yyyy,m,dd. The date is then printed in the format: yyyy-mm-dd. Hence the output is: 2017-07-24.

 

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

import datetime

d=datetime.date(2017,06,18)

print(d)

a) Error

b) 2017-06-18

c) 18-06-2017

d) 06-18-2017

Check Answer

Answer: a
The code shown above will result in an error because of the format of the date entered. Had the date been entered as: d=datetime.date(2017,6,18), no error would have been thrown.

 

48. What will be the output of the following Python code if the system date is 18th August, 2016?

tday=datetime.date.today()

print(tday.month())

a) August

b) Aug

c) 08

d) 8

Check Answer

Answer: d
The code shown above prints the month number from the system date. Therefor the output will be 8 if the system date is 18th August, 2016.

 

49. What will be the output of the following Python code if the system date is 18th June, 2017 (Sunday)?

import datetime

tday=datetime.date.today()

print(tday)

a) 18-06-2017

b) 06-18-2017

c) 2017-06-18

d) Error

Check Answer

Answer: c
The code shown above prints the system date in the format yyyy-mm-dd. Hence the output of this code is: 2017-06-18.

 

50. What will be the output of the following Python code if the system date is 18th June, 2017 (Sunday)?

tday=datetime.date.today()

print(tday.weekday())

a) 6

b) 1

c) 0

d) 7

Check Answer

Answer: a
The code shown above prints an integer depending on which day of the week it is. Monday-0, Tuesday-1, Wednesday-2, Thursday-3, Friday-4, Saturday-5, Sunday-6. Hence the output is 6 in the case shown above.

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

Leave a Comment