NEW
Font size
WorksheetsUSING PYTHON LIBRARIES
Total questions: 14
Worksheet time: 3mins
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)
Which of the following is equivalent to
random.randint(3, 6)?
a) random.choice([3, 6])
b) random.randrange(3, 6)
c) 3 + random.randrange(3)
d) 3 + random.randrange(4)
Which is the correct command to load just the tempc method from a module called usable ?
A. import usable , tempc
B. import tempc from usable
C. from usable import tempc
D. import tempc
Which file must be the part of the folder containing Python module files to make it importable python package ?
A. __main__.py
B. __init__.py
C. init.py
D. main.py
E. __package__.py
What is the output of the code shown below?
import sys sys.stdin.readline()
Sanfoundry
a) ‘Sanfoundry\n’
b) ‘Sanfoundry’
c) ‘Sanfoundry10’
d) Error
What would be the output produced by the following code ?
from math import factorial
print(math.factorial(5))
A.120
B. Nothing will get printed
C. 120.0
D. Error
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)
What possible output(s) are expected to be displayed on the screen at the time of execution of program from the following code ?
import random
print(100 + random.randint(5,10), end = " ")
print(100 + random.randint(5,10), end = " ")
print(100 + random.randint(5,10), end = " ")
print(100 + random.randint(5,10))
(i) 102 105 104 105
(ii) 110 103 104 105
(iii) 108 107 110 105
(iv) 110 110 110 110
A. (i) and (iii) are correct
B. (iii) and (iv) are correct
C. (ii) and (iv) are correct
D. (ii) and (iii) are correct
Suppose a function called add() is defined in a module called adder.py. Which of the following code snippets correctly show how to import and use the add() function?
A. from adder import add
result = adder.add(2, 3)
B. import adder
result = add(2, 3)
C. from adder import add
result = add(2, 3)
.D. import add from adder
result = add(2, 3)
Which of the following cannot be returned by random.randrange(4)?
a) 0
b) 3
c) 2.3
d) none of the mentioned
What is the output of the code shown below?
import sys eval(sys.stdin.readline())
Computer
a) Error
b) ‘Computer\n’
c) Computer8
d) Computer
What is the output of this code?
import sys eval(sys.stdin.readline()) "India"
a) India5
b) India
c) ‘India\n’
d) ‘India’
What is the output of the following line of code, if the sys module has already been imported in the interactive mode ?
sys.stdout.write("hello world")
a) helloworld
b) hello world10
c) hello world11
d) error
Which of the following functions is not defined under the sys module?
a) sys.platform
b) sys.path
c) sys.readline
d) sys.argv
