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
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.
Answered By
17 Likes