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

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

What is the expected behavior of the following code?

  • A. it outputs 0
  • B. the code is erroneous and it will not execute
  • C. it outputs 1
  • D. it outputs 2
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

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
Jos015
1 year ago
Selected Answer: D
ValueError s = '2A' try: n = int(s) except ValueError: n=2 except ArithmeticError: n=1 except: n=0 print (n)
upvoted 2 times
...
Rizos
1 year, 8 months ago
Can anyone explain what is happening here? why is the answer 2?
upvoted 1 times
noobplayer
1 year, 8 months ago
because it causes ValueError. you cannot cast the input to int because there is a character within
upvoted 3 times
...
...
macxsz
2 years, 6 months ago
Selected Answer: D
D. it outputs 2
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 ...