Answered You can hire a professional tutor to get the answer.

QUESTION

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

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

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

 a

larch

 b

break

 c

def

 d

raise

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

 a

larch outbreak

 b

bad grade

 c

infinite loop

 d

unhandled exception

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

 a

larch

 b

list

 c

equals

 d

as

 What kind of exception will the following code snippet throw?

>>> add(3,'hello')

 a

NameError

 b

AttributeError

 c

IOError

 d

NumberTypeError

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

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

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

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

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

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question