wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

python modules

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is a library in python?

a)

COLLECTION OF FILES

b)

COLLECTION OF MODULES

c)

IT IS SUBPROGRAM

d)

NAME OF A FILE

2.

exp(),floor()belongs which module?

a)

cmath.py

b)

urlib.py

c)

math.py

d)

statistics.py

3.

What will be the output of the following

from import factorial

print(math.factorial(5))

a)

25

b)

10

c)

120

d)

error bcz factorial is not a module in math

4.

Which of the statements is used to import all names from a module into the current calling module

a)

import

b)

from

c)

dir()

d)

import*

5.
Which of these definitions correctly describes a module?
a)
a) Denoted by triple quotes for providing the specification of certain program elements
b)
b) Design and implementation of specific functionality to be incorporated into a program
c)
c) Defines the specification of how it is to be used
d)
d) Any program that reuses code
6.
Which of the following is not an advantage of using modules?
a)
a) Provides a means of reuse of program code
b)
b) Provides a means of dividing up tasks
c)
c) Provides a means of reducing the size of the program
d)
d) Provides a means of testing individual parts of the program
7.
______ is a string literal denoted by triple quotes for providing the specifications of certain program elements.
a)
a) Interface
b)
b) Modularity
c)
c) Client
d)
d) Docstring
8.
A Python module is a file with the _____ file extension that contains valid Python code.
a)
.pymodule
b)
.py
c)
.module
d)
.pym
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? Select all that apply.

a)

import add from adder

result = add(2, 3)

b)

from adder import add

result = add(2, 3)

c)

from adder import add

result = adder.add(2, 3)

d)

import add

result = adder.add(2, 3)

10.

This code is equivalent to

a)

random.randint(1,11)

b)

random.randint(1,10)

c)

random.randrange(1,11,1)

d)

random.randrange(1,10,1)

11.

Name the keyword used to define a function.

a)

define

b)

def

c)

function

d)

fu

12.

Which one is not true about function?

a)

It breaks the large program into small modules.

b)

It avoids repetition.

c)

It makes code reusable.

d)

It makes the program unorganized.

13.

(a)   which function helps to display all information including docstring ,function name and constant in a module.

14.

random.randrange(6)

a)

0,1,2,3,4,5,6

b)

1,2,3,4,5,6

c)

0,1,2,3,4,5

d)

1,2,3,4,5

15.

random.randint(3,8)

a)

4,5,6,7

b)

3,4,5,6,7

c)

3,4,5,6,7,8

d)

0,1,2,3,4,5,6,7,8

16.

random.random() generates a floating point number between _____ and ______

a)

1 and 2

b)

1 and 0

c)

0 and 1

d)

0 and 10

17.

Which function truncates the fractional part of given number and returns only the integer or whole part.

a)

int()

b)

round()

c)

oct()

d)

hex()

18.

docstrings

a)

single quoted comments

b)

double quoted comments

c)

triple quoted comments

d)

hash tagged comments

19.

What will be the output of the following Python code?

def cube(x):

return x * x * x


x = cube(3)

print (x)

a)

9

b)

3

c)

27

d)

30

20.

What are the two main types of functions?

a)

Custom function

b)

Built-in function & User defined function

c)

User function

d)

System function