Python_Institute
PCEP-30-02 · Question #301
What is the expected output of the following code? x = (1, 4, 7, 9, 10, 11) y = {2: 'A', 4: 'B', 6: 'C', 8: 'D', 10: 'E', 12: 'F'} res = 1 for z in x: if z in y: res += z print(res)
The correct answer is A. 22. See the full explanation below for the reasoning.
Question
What is the expected output of the following code?
x = (1, 4, 7, 9, 10, 11)
y = {2: 'A', 4: 'B', 6: 'C', 8: 'D', 10: 'E', 12: 'F'}
res = 1
for z in x:
if z in y:
res += z
print(res)
Options
- A22
- B6
- C15
- D14
How the community answered
(63 responses)- A71% (45)
- B8% (5)
- C3% (2)
- D17% (11)
Community Discussion
No community discussion yet for this question.