Python MCQ’s on Modules: SET 10

91. What is the range of values that random.random() can return?

a) [0.0, 1.0]

b) (0.0, 1.0]

c) (0.0, 1.0)

d) [0.0, 1.0)

Check Answer

Answer: d
Any number that is greater than or equal to 0.0 and lesser than 1.0 can be returned.

92. Which of the following functions can help us to find the version of python that we are currently working on?

a) sys.version

b) sys.version()

c) sys.version(0)

d) sys.version(1)

Check Answer

Answer: a
The function sys.version can help us to find the version of python that we are currently working on. For example, 3.5.2, 2.7.3 etc. this function also returns the current date, time, bits etc along with the version.

93. Which of the following functions is not defined under the sys module?

a) sys.platform

b) sys.path

c) sys.readline

d) sys.argv

Check Answer

Answer: c
The functions sys.platform, sys.path and sys.argv are defined under the sys module. The function sys.readline is not defined. However, sys.stdin.readline is defined.

94. The output of the functions len(“abc”) and sys.getsizeof(“abc”) will be the same.

a) True

b) False

Check Answer

Answer: b
The function len returns the length of the string passed, and hence it’s output will be 3. The function getsizeof, present under the sys module returns the size of the object passed. It’s output will be a value much larger than 3. Hence the above statement is false.

95. What will be the output of the following Python code, if the code is run on Windows operating system?

import sys

if sys.platform[:2]== ‘wi’:

print(“Hello”)

a) Error

b) Hello

c) No output

d) Junk value

Check Answer

Answer: b
The output of the function sys.platform[:2] is equal to ‘wi’, when this code is run on windows operating system. Hence the output printed is ‘hello’.

96. What will be the output of the following Python code, if the sys module has already been imported?

sys.stdout.write(“hello world”)

a) helloworld

b) hello world10

c) hello world11

d) error

Check Answer

Answer: c
The function shown above prints the given string along with the length of the string. Hence the output of the function shown above will be hello world11.

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

import sys

sys.stdin.readline()

computer

a) ‘computer\n’

b) ‘computer’

c) ‘computer10’

d) Error

Check Answer

Answer: a
The function shown above works just like raw_input. Hence it automatically adds a ‘\n’ character to the input string. Therefore, the output of the function shown above will be: computer\n.

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

import sys

eval(sys.stdin.readline())

“India”

a) India5

b) India

c) ‘India\n’

d) ‘India’

Check Answer

Answer: d
The function shown above evaluates the input into a string. Hence if the input entered is enclosed in double quotes, the output will be enclosed in single quotes. Therefore, the output of this code is ‘India’.

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

import sys

eval(sys.stdin.readline())

Computer

a) Error

b) ‘Computer\n’

c) Computer8

d) Computer

Check Answer

Answer: a
The code shown above will result in an error. This is because this particular function accepts only strings enclosed in single or double inverted quotes, or numbers. Since the string entered above is not enclosed in single or double inverted quotes, an error will be thrown.

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

import sys

sys.argv[0]

a) Junk value

b) ‘ ‘

c) No output

d) Error

Check Answer

Answer: b
The output of the function shown above will be a blank space enclosed in single quotes. Hence the output of the code shown above is ‘ ‘.

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

Leave a Comment