Computer Science

Predict the output:


x, y = 20, 60
y, x, y = x, y - 10, x + 10
print (x, y)

Python

Python Funda

42 Likes

Answer

Output

50 30

Explanation

  1. x, y = 20, 60 ⇒ assigns an initial value of 20 to x and 60 to y.
  2. 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.
  3. print (x, y) ⇒ prints the value of x and y as 50 and 30 respectively.

Answered By

17 Likes


Related Questions