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

  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.

(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

  1. first = 2 ⇒ assigns an initial value of 2 to first.
  2. second = 3 ⇒ assigns an initial value of 3 to second.
  3. third = first * second ⇒ third = 2 * 3 = 6. So variable third is initialized with a value of 6.
  4. print (first, second, third) ⇒ prints the value of first, second, third as 2, 3 and 6 respectively.
  5. first = first + second + third ⇒ first = 2 + 3 + 6 = 11
  6. third = second * first ⇒ third = 3 * 11 = 33
  7. print (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

  1. side = int(input('side') ) ⇒ This statements asks the user to enter the side. We enter 7 as the value of side.
  2. area = side * side ⇒ area = 7 * 7 = 49.
  3. print (side, area) ⇒ prints the value of side and area as 7 and 49 respectively.
Answer