# 1 Consider the following code. What is the output of divide(2,4)?

1 Consider the following code. What is the output of divide(2,4)?

def divide(a, b):

z = -1

try:

z = a / b

except ZeroDivisionError:

print(‘Can not divide by zero’)

finally:

print(‘Result is’, z)

a Cannot divide by zero. Result is -1

b Result is 0.5

c Result is 2

d Cannot divide by zero. Result is 2

2 Programmers can force their programs to throw an exception by using the _________ statement.

a larch

b break

c def

d raise

3 If no exception handler exists for an error type, then a(n) _______ may occur.

a larch outbreak

c infinite loop

d unhandled exception

4 The _________ keyword binds a name to the exception being handled.

a larch

b list

c equals

d as

5 What kind of exception will the following code snippet throw?

a NameError

b AttributeError

c IOError

d NumberTypeError

6 What is the output of the following code snippet?

class B(Exception):

pass

class C(B):

pass

class D(C):

pass

for cls in [B, C, D]:

try:

raise cls()

except D:

print(“D”)

except C:

print(“C”)

except B:

print(“B”)

a B C D

b C D B

c D B C

d B

7 What kind of error will the following code segment throw?

(x,y) = (3.14159,0)

z = x/y

a A Larch

b A ValueError

c A ZeroDivisionError

d A DivideByZeroError

8 Consider the following code. What is the output of divide(0,1)?

def divide(a, b):

z = -1

try:

z = a / b

except ZeroDivisionError:

print(‘Can not divide by zero’)

finally:

print(‘Result is’, z)

a Cannot divide by zero. Result is -1

b Result is 0.0

c Result is 0

d Cannot divide by zero. Result is 0

9 An AttributeError occurs if a function does not exist in an imported module. Fill in the missing code to handle AttributeErrors gracefully and generate an error if other types of exceptions occur.

import my_lib

try:

result = my_lib.larch()

____________:

print(‘No larch() function in my_lib.’)

a larch AttributeError

b except AttributeError

c AttributeError

d except

10 If a programmer chooses not to use a built-in exception type, then she may use a ___________

exception type.

a larch

b custom

c finally

d default

(550 words)

Approximate price: \$22

## How it Works

1

It only takes a couple of minutes to fill in your details, select the type of paper you need (essay, term paper, etc.), give us all necessary information regarding your assignment.

2

Once we receive your request, one of our customer support representatives will contact you within 24 hours with more specific information about how much it'll cost for this particular project.

3

After receiving payment confirmation via PayPal or credit card – we begin working on your detailed outline, which is based on the requirements given by yourself upon ordering.

4

Once approved, your order is complete and will be emailed directly to the email address provided before payment was made!