Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.

Unlimited Access

Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.

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 (?) , you can switch to a simple comment.
Switch to a voting comment New
Efren
Highly Voted 2 years, 5 months 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 2 months, 2 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
2 months, 3 weeks 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
9 months, 1 week 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
11 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
1 year, 11 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
1 year, 11 months ago
Selected Answer: A
A. it raises an exception strong variable does not exist
upvoted 3 times
...
DTL001
2 years, 4 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, 1 month ago
I tried running your code and still got the exception "IndentationError: expected an indented block"
upvoted 1 times
...
Ton123
2 years ago
it is: dummy = character + dummy. Then the output will be 0.
upvoted 1 times
...
...
lukaki
2 years, 4 months 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 ...