CBSE Class 9 Computer Applications Question 10 of 23

Introducing Python — Question 3

Back to all questions
3
Question

Question 3(i)

What will be the output produced by following code fragment ?

X = 10
X = X + 10
X = X - 5
print X
X, Y = X - 2, 22
print X, Y
Answer
Output
15
13 22
Explanation
  1. X = 10 ⇒ assigns an initial value of 10 to X.
  2. X = X + 10 ⇒ X = 10 + 10 = 20. So value of X is now 20.
  3. X = X - 5 ⇒ X = 20 - 5 = 15. X is now 15.
  4. print (X) ⇒ print the value of X which is 15.
  5. X, Y = X - 2, 22 ⇒ X, Y = 13, 22.
  6. print (X, Y) ⇒ prints the value of X which is 13 and Y which is 22.