Question 2
Consider the below code snippet.
def updated_val(d, key, val):
if key in d:
d[key] += val
else:
d[key] = val
return d[key]
my_dict = {'a': 2, 'b': 3}
print(
updated_val(my_dict, 'c', 4)
+ updated_val(my_dict, 'c', 2)
+ updated_val(my_dict, 'a', 2)
)
What will be the output of the above code
6
14
10
Raises KeyError