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

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

What is the expected behavior of the following code?

  • A. it raises an exception
  • B. it outputs 0
  • C. it outputs 3
  • D. it outputs 'None'
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

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
Efren
Highly Voted 3 years ago
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
upvoted 8 times
...
zantrz
Most Recent 9 months, 4 weeks ago
Selected Answer: 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.
upvoted 1 times
...
seaverick
10 months ago
Selected Answer: 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
upvoted 1 times
...
CC_DC
1 year, 4 months ago
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.
upvoted 1 times
...
kontra
1 year, 6 months ago
Selected Answer: B
If strong is a typo and is actually string, dummy = 333333333333333.0 So the answer is B: 0
upvoted 3 times
...
Siva_2022
2 years, 6 months ago
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])
upvoted 1 times
...
macxsz
2 years, 6 months ago
Selected Answer: A
A. it raises an exception strong variable does not exist
upvoted 3 times
...
DTL001
2 years, 11 months ago
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'>
upvoted 1 times
grinha
2 years, 8 months ago
I tried running your code and still got the exception "IndentationError: expected an indented block"
upvoted 1 times
...
Ton123
2 years, 8 months ago
it is: dummy = character + dummy. Then the output will be 0.
upvoted 1 times
...
...
lukaki
3 years ago
If there is: for character in strong: Answer is A If there is: for character in string: Answer is B
upvoted 2 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 ...