wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Exception ✋

Total questions: 12

Worksheet time: 6mins

Name
Class
Date
1.

How many except statements can a try-except block have?

a)

Zero

b)

One

c)

Two

d)

Multiples

2.

When will the else part of try-except-else be executed?

a)

always

b)

when an exception occurs

c)

when no exception occurs

d)

never

3.

When is the finally block executed?

a)

when an exception occurs

b)

when no exception occurs

c)

never

d)

always

4.

Can one except block handle multiple exceptions?

a)

Yes

b)

No

c)

May be

d)

Insufficient information

5.

Which of the following is correct regarding exception

a)

That may occur any time

b)

That occurs before execution

c)

That occurs after execution

d)

That occurs during execution

6.

ZeroDivisionError may occur during which operation

a)

Division

b)

Modulo

c)

Both

d)

None

7.

Exception handling in python is done using ___ blocks

a)

try

b)

except

c)

else

d)

finally

8.
What is the last action that must be performed on a file?
a)
Close
b)
Save
c)
End
d)
Write
9.

Is the following Python code valid?

try:

# Do something

except:

# Do something

finally:

# Do something

a)

Yes

b)

No

10.

Is the following code is vaild ?


try:

1 / 0

except:

print('exception')

else:

print('else')

finally:

print('finally')

a)

Yess

b)

No

c)

Maybe

11.

What is the output of the following code ?

try:

if '2' != 2:

raise ValueError

else:

print('same')

except ValueError:

print('ValueError')

except NameError:

print('NameError')

a)

Value Error

b)

Name Error

c)

Both

d)

None of the above

12.

If there is an error in opening a file, which exception is raised ?

a)

Index Error

b)

IO Error

c)

Import Error

d)

Type Error