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 84 discussion

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

What is true about the following snippet? (Choose two.)

  • A. the string it's nice to see you will be seen
  • B. the string I feel fine will be seen
  • C. the code will raise an unhandled exception
  • D. the string what a pity will be seen
Show Suggested Answer Hide Answer
Suggested Answer: BD 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
rotimislaw
Highly Voted 1 year, 5 months ago
Selected Answer: BC
B. the string I feel fine will be seen - it happens before any exception is raised C. unhandled exception is raised and writes down "Exception: what a pity", not only "what a pity" as the answer D states
upvoted 7 times
...
Damon54
Most Recent 2 months, 2 weeks ago
The code could also be like this perhaps class E(Exception): def __init__(self, message): self.message = message def __str__(self): return "It's nice to see you" try: print("I feel fine") raise Exception("what a pity") except Exception as e: print(e) else: print("the show must go on")
upvoted 1 times
...
zantrz
2 months, 3 weeks ago
Selected Answer: BC
The raise Exception("What a pity") line raises a generic Exception, not an instance of the custom exception E. Since the except E as e block is specifically looking for instances of E, it won't catch the raised exception, and the control will go directly to the else block. However! The program terminates abruptly after encountering the unhandled Exception, and the else block doesn't get a chance to execute. When an unhandled exception occurs, the normal program flow is disrupted, and subsequent code (including the else block) is skipped. To make the else block execute, you would need to handle the exception, either by catching it with the correct except block or allowing the program to handle it at a higher level.
upvoted 1 times
...
mplopez
8 months ago
Selected Answer: BD
The B option is correct because the string I feel fine is printed on screen, and the D option is printed too.
upvoted 1 times
...
macxsz
1 year, 11 months ago
Selected Answer: BD
B. the string I feel fine will be seen D. the string what a pity will be seen
upvoted 3 times
...
TheNetworkStudent
2 years, 1 month ago
Selected Answer: BD
Although answer B, C and D are correct. I think B and D are the 'best' answers. Because C an unhandled exception is raised, D is true. B is true because the line is printed before C and D happen.
upvoted 3 times
...
sadako11
2 years, 2 months ago
the message 'I fell fine' will be seen and the code will raise an unhandled exception and the message 'what a pity ' will be seen. The answers could be B,C or D
upvoted 1 times
...
DTL001
2 years, 4 months ago
Answer in BD, I've tested: class E(Exception): def __init__(self, message): self.message = message def __str__(self): return "It's nice to see you" try: print("I fell fine") raise Exception("What a party") except E as e: print(e) else: print("the show must go on") #Output: #I fell fine #Traceback (most recent call last): # File "C:\devops\python\t.py", line 9, in <module> # raise Exception("What a party") #Exception: What a party
upvoted 2 times
...
luckymuki
2 years, 6 months ago
The answer is B,C
upvoted 3 times
techdawgs
2 years, 4 months ago
It actually is BD. The string "what a pity" is the error message displayed so technically it will be seen along with "I feel fine".
upvoted 1 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 ...