CBSE Class 11 Informatics Practices Question 32 of 75

Conditional and Looping Constructs — Question 4

Back to all questions
4
Question

Question 4(a)

Give the output of the following when num1 = 4, num2 = 3, num3 = 2.

num1 += num2 + num3
print(num1)
Answer
Output
9
Explanation

In the above code, num1 += num2 + num3 is a shorthand notation for num1 = num1 + num2 + num3.

Given,

num1 = 4
num2 = 3
num3 = 2

First, the expression num2 + num3 is evaluated:

num2 + num3 = 3 + 2 = 5

Now the expression becomes:

num1 = num1 + 5

which translates to:

num1 = 4 + 5 = 9