PCAP-31-03 Exam QuestionsBrowse all questions from this exam

PCAP-31-03 Exam - Question 14


What is the expected behavior of the following code?

Show Answer
Correct Answer: A

The code converts the result of 1/3 to a string, which usually evaluates to '0.3333333333333333'. It then iterates over each character in this string, constructing a new string 'dummy' that is the same as 'string'. Finally, it prints the last character of 'dummy', which corresponds to the last character in the string representation of 1/3. Therefore, the output is '3'.

Discussion

3 comments
Sign in to comment
kstrOption: A
Jun 5, 2024

Correct answer is A string = str(1/3) dummy = '' for character in string: dummy = dummy + character print (dummy [-1])

Dave304409Option: A
Jul 2, 2024

A is correct

DKAT2023Option: A
Jun 28, 2024

A is correct