Exam PCAP All QuestionsBrowse all questions from this exam
Question 87

What is the expected behavior of the following code?

    Correct Answer: A

    A

Discussion
EfrenOption: B

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

kontraOption: B

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

macxszOption: A

A. it raises an exception strong variable does not exist

lukakiOption: A

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

zantrzOption: A

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.

seaverickOption: A

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

CC_DCOption: A

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.

Siva_2022Option: B

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])

DTL001Option: B

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

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

Ton123

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