exam questions

Exam PCAP-31-03 All Questions

View all questions & answers for the PCAP-31-03 exam

Exam PCAP-31-03 topic 1 question 49 discussion

Actual exam question from Python Institute's PCAP-31-03
Question #: 49
Topic #: 1
[All PCAP-31-03 Questions]

What is the expected behavior of the following code?

  • A. it outputs 123
  • B. it raises an exception
  • C. it outputs 6
  • D. it outputs 321
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

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
Abbribas
1 month, 2 weeks ago
Selected Answer: C
Initialization: string = '123' dummy = 0 reversed(string): The reversed() function returns a reverse iterator for the string '123'. The characters will be iterated in the order: '3', '2', '1'. Loop Iteration 1: character is assigned the value '3'. int(character) converts '3' to the integer 3. dummy += 3 is executed. dummy becomes 0 + 3 = 3. Loop Iteration 2: character is assigned the value '2'. int(character) converts '2' to the integer 2. dummy += 2 is executed. dummy becomes 3 + 2 = 5. Loop Iteration 3: character is assigned the value '1'. int(character) converts '1' to the integer 1. dummy += 1 is executed. dummy becomes 5 + 1 = 6. Loop ends: The loop has iterated through all the characters in the reversed string. print(dummy): The final value of dummy, which is 6, is printed.
upvoted 1 times
...
Dave304409
1 year ago
Selected Answer: C
is correct
upvoted 2 times
...
DKAT2023
1 year, 1 month ago
Selected Answer: C
C is correct
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 ...