hiexam
python-institute · PCEP-30-02 · Q604 · multiple_choice · topic_1

What is the output of the following snippet? //IMG//

What is the output of the following snippet? //IMG//
  • A.two
  • B.one
  • C.(‘one’, ‘two’, ‘three’)
  • D.three
Explanation
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

Reference: examtopics_top_comment

Practice with progress tracking

Sign in to track wrong answers, get spaced-repetition reminders, and run timed exam mode.