CBSE Class 11 Computer Science
Question 75 of 106
Python Fundamentals — Question 4
Back to all questions 4
Question Question 4
What will be the output produced by following code fragment (s) ?
(i)
X = 10
X = X + 10
X = X - 5
print (X)
X, Y = X - 2, 22
print (X, Y) Output
15
13 22
Explanation
X = 10⇒ assigns an initial value of 10 to X.X = X + 10⇒ X = 10 + 10 = 20. So value of X is now 20.X = X - 5⇒ X = 20 - 5 = 15. X is now 15.print (X)⇒ print the value of X which is 15.X, Y = X - 2, 22⇒ X, Y = 13, 22.print (X, Y)⇒ prints the value of X which is 13 and Y which is 22.
(ii)
first = 2
second = 3
third = first * second
print (first, second, third)
first = first + second + third
third = second * first
print (first, second, third)Output
2 3 6
11 3 33
Explanation
first = 2⇒ assigns an initial value of 2 to first.second = 3⇒ assigns an initial value of 3 to second.third = first * second⇒ third = 2 * 3 = 6. So variable third is initialized with a value of 6.print (first, second, third)⇒ prints the value of first, second, third as 2, 3 and 6 respectively.first = first + second + third⇒ first = 2 + 3 + 6 = 11third = second * first⇒ third = 3 * 11 = 33print (first, second, third)⇒ prints the value of first, second, third as 11, 3 and 33 respectively.
(iii)
side = int(input('side') ) #side given as 7
area = side * side
print (side, area)Output
side7
7 49
Explanation
side = int(input('side') )⇒ This statements asks the user to enter the side. We enter 7 as the value of side.area = side * side⇒ area = 7 * 7 = 49.print (side, area)⇒ prints the value of side and area as 7 and 49 respectively.