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

Unlimited Access

Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.

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 🗳️
Reference:
https://www.programiz.com/python-programming/exception-handling

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
kauser
Highly Voted 3 years, 8 months ago
Answer is C, but with brackets inserted around (Ex1, Ex2) - or B uppercase Ex1
upvoted 8 times
...
seaverick
Most Recent 2 months, 3 weeks 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
1 year, 11 months ago
Selected Answer: B
B. except (Ex1, Ex2):
upvoted 3 times
...
rocky48
2 years ago
Selected Answer: B
b. except (Ex1, Ex2):
upvoted 1 times
...
technoguy
2 years, 4 months ago
B is corrrect answer
upvoted 1 times
...
DKM
2 years, 5 months 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
2 years, 5 months 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
2 years, 6 months ago
Should be D
upvoted 1 times
...
Brodeh
3 years, 1 month ago
Answer should be A
upvoted 1 times
...
Fulano_de_tal
3 years, 1 month ago
The Answer is D: try: pass except TypeError+ZeroDivisionError: pass except: pass
upvoted 3 times
leonardodicaprio
2 years, 10 months ago
ur code is giving issue. It can't be an answer
upvoted 2 times
...
...
BenKa
3 years, 8 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 ...