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 (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
hovnival
1 month, 2 weeks ago
Selected Answer: A
Step-by-step Execution: Initialization: dictionary is a dictionary: {'one': 'two', 'three': 'one', 'two': 'three'}. v is initialized to dictionary['one'], which is 'two'. For Loop Iterations: First iteration (k = 0): Current value of v is 'two'. v = dictionary['two'] → 'two' maps to 'three'. So, v = 'three'. Second iteration (k = 1): Current value of v is 'three'. v = dictionary['three'] → 'three' maps to 'one'. So, v = 'one'. Third iteration (k = 2): Current value of v is 'one'. v = dictionary['one'] → 'one' maps to 'two'. So, v = 'two'. Final Value of v: After 3 iterations, the value of v is 'two'. Output: The print(v) statement outputs 'two'.
upvoted 2 times
...
consultsk
4 months, 1 week 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 2 times
...
megan_mai
5 months, 2 weeks 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
5 months, 2 weeks 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 ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago