Exam PCAP All QuestionsBrowse all questions from this exam
Question 67

If you need to serve two different exceptions called Ex1 and Ex2 in one except branch, you can write:

    Correct Answer: B

    If you need to handle multiple exceptions in a single except branch in Python, you should use parentheses to group them. Writing 'except (Ex1, Ex2):' correctly instructs Python to handle both Ex1 and Ex2 exceptions. This syntax allows you to specify a tuple of exception classes that the except clause will catch, making option B the correct choice.

Discussion
kauserOption: B

Answer is C, but with brackets inserted around (Ex1, Ex2) - or B uppercase Ex1

macxszOption: B

B. except (Ex1, Ex2):

Fulano_de_talOption: D

The Answer is D: try: pass except TypeError+ZeroDivisionError: pass except: pass

leonardodicaprio

ur code is giving issue. It can't be an answer

rbishunOption: B

# Answer is B. Point of Q is, you need to use () with except when more than 1. try: # TypeError: can only concatenate str (not "int") to str print( 'five' + 1 ) # ZeroDivisionError: division by zero print ( 5 / 0) except (TypeError, ZeroDivisionError): print('An error occured.')

BenKaOption: B

B should be the answer, but aren't the Exception name case sensitive? In which case, B is not the answer.

seaverickOption: B

try: # TypeError: can only concatenate str (not "int") to str print( 'five' + 1 ) # ZeroDivisionError: division by zero print ( 5 / 0) except (TypeError, ZeroDivisionError): #correct #except TypeError, ZeroDivisionError: #SyntaxError: multiple exception types must be parenthesized #except TypeError ZeroDivisionError: #SyntaxError: invalid syntax #except TypeError + ZeroDivisionError: #TypeError: unsupported operand type(s) for +: 'type' and 'type' print('An error occured.') Output - An error ocurred Ans is B

rocky48Option: B

b. except (Ex1, Ex2):

technoguyOption: B

B is corrrect answer

DKMOption: B

If you need to serve two different exceptions called Ex1 and Ex2 in one except branch, you can write: a. except Ex1 Ex2: b. except (Ex1, Ex2): c. except Ex1, Ex2: d. except Ex1 + Ex2:

tanstOption: D

Should be D

BrodehOption: A

Answer should be A