CBSE Class 11 Computer Science
Question 77 of 106
Python Fundamentals — Question 6
Back to all questions 6
Question Question 6
Predict the output:
(a)
x = 40
y = x + 1
x = 20, y + x
print (x, y)Output
(20, 81) 41
Explanation
x = 40⇒ assigns an initial value of 40 to x.y = x + 1⇒ y = 40 + 1 = 41. So y becomes 41.x = 20, y + x⇒ x = 20, 41 + 40 ⇒ x = 20, 81. This makes x a Tuple of 2 elements (20, 81).print (x, y)⇒ prints the tuple x and the integer variable y as (20, 81) and 41 respectively.
(b)
x, y = 20, 60
y, x, y = x, y - 10, x + 10
print (x, y)Output
50 30
Explanation
x, y = 20, 60⇒ assigns an initial value of 20 to x and 60 to y.y, x, y = x, y - 10, x + 10
⇒ y, x, y = 20, 60 - 10, 20 + 10
⇒ y, x, y = 20, 50, 30
First RHS value 20 is assigned to first LHS variable y. After that second RHS value 50 is assigned to second LHS variable x. Finally third RHS value 30 is assigned to third LHS variable which is again y. After this assignment, x becomes 50 and y becomes 30.- print (x, y) ⇒ prints the value of x and y as 50 and 30 respectively.
(c)
a, b = 12, 13
c, b = a*2, a/2
print (a, b, c)Output
12 6.0 24
Explanation
a, b = 12, 13⇒ assigns an initial value of 12 to a and 13 to b.c, b = a*2, a/2⇒ c, b = 12*2, 12/2 ⇒ c, b = 24, 6.0. So c has a value of 24 and b has a value of 6.0.print (a, b, c)⇒ prints the value of a, b, c as 12, 6.0 and 24 respectively.
(d)
a, b = 12, 13
print (print(a + b))Output
25
None
Explanation
a, b = 12, 13⇒ assigns an initial value of 12 to a and 13 to b.print (print(a + b))⇒ First print(a + b) function is called which prints 25. After that, the outer print statement prints the value returned by print(a + b) function call. As print function does not return any value so outer print function prints None.