wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Functions & Library

Total questions: 12

Worksheet time: 12mins

Name
Class
Date
1.

Consider the following code:

a)

0

b)

1

c)

2

2.

Consider the following code:

a)

1 2 2

b)

2 1 2

c)

4 2 2

3.

What is the output of the following code snippet?

a)

1 3

b)

2 3

c)

The program has a runtime error because x and y are not defined.

d)

3 2

e)

3 3

4.

What is the output of the following piece of code?

a)

4

b)

5

c)

1

d)

An exception is thrown

5.

What is the output of the below program?

a)

x is 50Changed global x to 2Value of x is 50

b)

x is 50Changed global x to 2Value of x is 2

c)

x is 50Changed global x to 50Value of x is 50

d)

None of the mentioned

6.

What is the output of the function shown below (random module has already been imported)?


random.choice('sun')

a)

sun

b)

either s,u or n

c)

u

d)

Error

7.

A package is a folder containing one or more Python modules. One of the modules in a package must be called _______.

a)

__package__.py

b)

init.py

c)

main.py

d)

__init__.py

e)

__main__.py

8.

What is output of following code?

a)

i i i i i i i i……..

b)

m m m m m …..

c)

m n o p q r

d)

No output

9.

What is the output of the code?

a)

-300 -100

b)

200 0

c)

200 100

d)

0 300

10.

What is the value of a, b, c in the given below code?

a, b = c = 2 + 2, ''TutorialsPoint''

a)

a=4, 'TutorialsPoint'

b= 4, 'TutorialsPoint'

c= 4, 'TutorialsPoint'

b)

a=2

b= 'TutorialsPoint'

c=4, 'TutorialsPoint'

c)

a=4

b= 'TutorialsPoint'

c=4, 'TutorialsPoint'

d)

a=4

b= 'TutorialsPoint'

c= NULL

11.

Choose the correct output for this code:

a)

1

b)

2

c)

4

d)

16

e)

256

12.

What is the output of this code?

def func(val1, val2=2, val3=7, val4=1):

return val1**val2**val3


print(func(val2=2, val1=2, val3=4))

a)

256

b)

32768

c)

65536

d)

This code raises an exception