# PCEP-30-02 — Question 603

**Type:** multiple_choice
**Topics:** topic_1

## Question

What will be the output of the following code snippet?
//IMG//

## Correct Answer

_See scenario._

## Explanation

Selected Answer: C
Let's analyze this code step by step:

d = {} creates an empty dictionary.
d[1] = 1 adds a key-value pair where the key is the integer 1 and the value is 1.
d['1'] = 2 adds another key-value pair where the key is the string '1' and the value is 2.
d[1] += 1 increments the value associated with the key 1. So now d[1] becomes 2.
sum = 0 initializes a variable sum to 0.
The for loop for k in d: iterates over the keys in the dictionary.
In each iteration, it adds the value associated with the current key to sum.

After the loop, sum will contain:

2 (from d[1])
2 (from d['1'])

Therefore, the final value of sum will be 4.

print(sum) will output this final value.

So, the output of this code will be: 4

**Reference:** examtopics_top_comment

---
Source: https://hiexam.net/q/python-institute/PCEP-30-02/603  
Practice (tracked): https://hiexam.net/study/PCEP-30-02/practice