wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

PYTHON EXCEPTION

Total questions: 13

Worksheet time: 7mins

Name
Class
Date
1.

The unexpected event happened during program execution should be handled by

a)

EXCEPTION

b)

EXPERIMENT

c)

ASSERTION

d)

EXTRAORDINARY

2.

try:

a=int(input("\n Enter a Value"))

b=int(input("\n Enter a Value "))

c=a/b

print (c)

except:

print("\n Something Went Wrong")


Assume a = 10 and b = 5, then the output will be

a)

5.0

b)

Something Went Wrong

c)

Arithmetic Error

d)

2.0

3.

Exception disrupts the

a)

Normal flow of the program

b)

Abnornal flow of the program

c)

Hard Disk

d)

None of the Above

4.

The suspicious code is put inside the

a)

Try Block

b)

Finally Block

c)

Else Block

d)

Except Block

5.

________ statement can also be used without specifying Exception.

a)

Try

b)

Finally

c)

Except

d)

Else

6.

try:

a=10/5

print (a)

except ArithmeticError:

print ("This statement is raising an exception" )

finally:

print (" final block executed " )

a)

2.0

final block executed

b)

This statement is raising an exception

final block executed

c)

final block executed

d)

2.0

7.

An exception can be manually triggered by the command

a)

raise

b)

try

c)

except

d)

trigger

8.

User defined Exceptions are created from the _________ Parent Class

a)

Exception

b)

Except

c)

Handler

d)

User Defined Exception

9.

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

a)

zero

b)

one

c)

more than one

d)

more than zero

10.

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

a)

a) always

b)

b) when an exception occurs

c)

c) when no exception occurs

d)

d) when an exception occurs in to except block

11.

Is the following Python code valid?


try:

# Do something

except:

# Do something

else:

# Do something

a)

no, there is no such thing as else

b)

no, else cannot be used with except

c)

no, else must come before except

d)

yes

12.

What will be the output of the following Python code?


lst = [1, 2, 3]

lst[3]

a)

a) NameError

b)

b) ValueError

c)

c) IndexError

d)

d) TypeError

13.

What will be the output of the following Python code?


lst = [1, 2, 3]

lst[3]

a)

a) NameError

b)

b) ValueError

c)

c) IndexError

d)

d) TypeError