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

Exam PCEP-30-02 All Questions

View all questions & answers for the PCEP-30-02 exam

Exam PCEP-30-02 topic 1 question 11 discussion

Actual exam question from Python Institute's PCEP-30-02
Question #: 11
Topic #: 1
[All PCEP-30-02 Questions]

What is the output of the following snippet?

  • A. two
  • B. one
  • C. (‘one’, ‘two’, ‘three’)
  • D. three
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
consultsk
1 month, 3 weeks ago
Selected Answer: A
Let's analyze this code step by step: A dictionary is created with key-value pairs: 'one': 'two' 'three': 'one' 'two': 'three' v is initially set to dictionary['one'], which is 'two'. The for loop runs for range(len(dictionary)), which is range(3) since the dictionary has 3 key-value pairs. Inside the loop, v = dictionary[v] is executed 3 times: First iteration: v = dictionary['two'] = 'three' Second iteration: v = dictionary['three'] = 'one' Third iteration: v = dictionary['one'] = 'two' After the loop, the final value of v is 'two'. print(v) outputs this final value. Therefore, the output of this code will be: two
upvoted 1 times
...
megan_mai
3 months ago
Selected Answer: A
dictionary = {'one': 'two', 'three': 'one', 'two': 'three'} v = dictionary['one'] >> v = 'two' (the value of key 'one') for k in range(len(dictionary)): >> this loop will be run 3 times when k=0, k=1 and k=2 v = dictionary[v] >> loop 1 - k=0: v='two' >> dictionary(v) = 'three' >> new v = 'three' >> loop 2 - k=1: v= 'three' >> dictionary(v) = 'one' >> new v = 'one' >> loop 3 - k=2: v='one' >> dictionary(v) = 'two' >> new v = 'two' print(v) >> printed value is the newest v = 'two' (A)
upvoted 1 times
...
christostz03
3 months ago
a is the correct answer
upvoted 1 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 ...