wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

USING PYTHON LIBRARIES

Total questions: 14

Worksheet time: 3mins

Name
Class
Date
1.

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

a)

a) [0.0, 1.0].

b)

b) (0.0, 1.0].

c)

c) (0.0, 1.0)

d)

d) [0.0, 1.0)

2.

Which of the following is equivalent to


random.randint(3, 6)?

a)

a) random.choice([3, 6])

b)

b) random.randrange(3, 6)

c)

c) 3 + random.randrange(3)

d)

d) 3 + random.randrange(4)

3.

Which is the correct command to load just the tempc method from a module called usable ?

a)

A. import usable , tempc

b)

B. import tempc from usable

c)

C. from usable import tempc

d)

D. import tempc

4.

Which file must be the part of the folder containing Python module files to make it importable python package ?

a)

A. __main__.py

b)

B. __init__.py

c)

C. init.py

d)

D. main.py

e)

E. __package__.py

5.

What is the output of the code shown below?


import sys sys.stdin.readline()

Sanfoundry

a)

a) ‘Sanfoundry\n’

b)

b) ‘Sanfoundry’

c)

c) ‘Sanfoundry10’

d)

d) Error

6.

What would be the output produced by the following code ?

from math import factorial

print(math.factorial(5))

a)

A.120

b)

B. Nothing will get printed

c)

C. 120.0

d)

D. Error

7.

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

a)

a) sys.version

b)

b) sys.version()

c)

c) sys.version(0)

d)

d) sys.version(1)

8.

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)

A. (i) and (iii) are correct

b)

B. (iii) and (iv) are correct

c)

C. (ii) and (iv) are correct

d)

D. (ii) and (iii) are correct

9.

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)

A. from adder import add


result = adder.add(2, 3)

b)

B. import adder


result = add(2, 3)

c)

C. from adder import add


result = add(2, 3)

d)

.D. import add from adder


result = add(2, 3)

10.

Which of the following cannot be returned by random.randrange(4)?

a)

a) 0

b)

b) 3

c)

c) 2.3

d)

d) none of the mentioned

11.

What is the output of the code shown below?


import sys eval(sys.stdin.readline())

Computer

a)

a) Error

b)

b) ‘Computer\n’

c)

c) Computer8

d)

d) Computer

12.

What is the output of this code?


import sys eval(sys.stdin.readline()) "India"

a)

a) India5

b)

b) India

c)

c) ‘India\n’

d)

d) ‘India’

13.

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)

a) helloworld

b)

b) hello world10

c)

c) hello world11

d)

d) error

14.

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

a)

a) sys.platform

b)

b) sys.path

c)

c) sys.readline

d)

d) sys.argv