PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 87


What is the expected behavior of the following code?

Show Answer
Correct Answer: A

A

Discussion

9 comments
Sign in to comment
EfrenOption: B
Nov 12, 2021

If im not wrong, is B) string=str(1/3) ---- this is equal a 0.3333333333 dummy='' >>> for character in string: dummy=character+dummy >>> dummy '3333333333333333.0' print(dummy[-1])----- this is 0

macxszOption: A
May 4, 2022

A. it raises an exception strong variable does not exist

kontraOption: B
May 24, 2023

If strong is a typo and is actually string, dummy = 333333333333333.0 So the answer is B: 0

lukakiOption: A
Nov 25, 2021

If there is: for character in strong: Answer is A If there is: for character in string: Answer is B

DTL001Option: B
Dec 19, 2021

Answer is B: string = str(1/3) dummy = '' for character in string: dummy = dummy + character print(dummy[-1]) # 3 # In python all types are classses print(type(dummy)) # <class 'str'>

grinha
Mar 15, 2022

I tried running your code and still got the exception "IndentationError: expected an indented block"

Ton123
Mar 31, 2022

it is: dummy = character + dummy. Then the output will be 0.

Siva_2022Option: B
May 15, 2022

It outputs 0. string=str(1/3) print("string=",string) dummy='' for character in string: print("character=",character) dummy=character+dummy print("dummy=",dummy) print(dummy[-1])

CC_DCOption: A
Jul 12, 2023

A is right if the variable name us strong but if corrected to string (no sure if this a typo or intentional), then the result is 0.

seaverickOption: A
Jan 27, 2024

string = str(1/3) dummy='' for character in strong: dummy=character + dummy print(dummy[-1]) Output -> NameError: name 'strong' is not defined Ans A

zantrzOption: A
Feb 3, 2024

dummy = character + dummy: Adds the current character to the BEGINNING of the dummy string, effectively reversing the order of characters. print(dummy[-1]): Prints the last character of the reversed string, which is the first character of the original string.