Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam PCAP All Questions

View all questions & answers for the PCAP exam

Exam PCAP topic 1 question 67 discussion

Actual exam question from Python Institute's PCAP
Question #: 67
Topic #: 1
[All PCAP Questions]

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:
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
kauser
Highly Voted 4 years, 3 months ago
Answer is C, but with brackets inserted around (Ex1, Ex2) - or B uppercase Ex1
upvoted 8 times
...
seaverick
Most Recent 10 months ago
Selected Answer: 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
upvoted 1 times
...
macxsz
2 years, 6 months ago
Selected Answer: B
B. except (Ex1, Ex2):
upvoted 3 times
...
rocky48
2 years, 7 months ago
Selected Answer: B
b. except (Ex1, Ex2):
upvoted 1 times
...
technoguy
3 years ago
B is corrrect answer
upvoted 1 times
...
DKM
3 years ago
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:
upvoted 1 times
...
rbishun
3 years ago
# 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.')
upvoted 2 times
...
tanst
3 years, 1 month ago
Should be D
upvoted 1 times
...
Brodeh
3 years, 8 months ago
Answer should be A
upvoted 1 times
...
Fulano_de_tal
3 years, 8 months ago
The Answer is D: try: pass except TypeError+ZeroDivisionError: pass except: pass
upvoted 3 times
leonardodicaprio
3 years, 5 months ago
ur code is giving issue. It can't be an answer
upvoted 2 times
...
...
BenKa
4 years, 3 months ago
B should be the answer, but aren't the Exception name case sensitive? In which case, B is not the answer.
upvoted 2 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...