Informatics Practices
Give the output.
x = 40
y = x + 1
x, y = 20, y + x
print (x, y)
Python Funda
2 Likes
Answer
20 81
Working
x = 40
y = x + 1
xis initialized to 40.yis set tox + 1, which means y = 40 + 1 = 41.
x, y = 20, y + x
The values of x and y are updated simultaneously. This means both assignments are evaluated first and then applied.
- The left-hand side of the assignment is
x, y. - The right-hand side is
20, y + x. xis set to 20.yis set toy + x, which means y = 41 + 40 = 81.
print(x, y)
The final values of the variables are:
- x = 20
- y = 81
Hence, the output of the program is:
20 81
Answered By
3 Likes
Related Questions
Find errors in the following code fragment.
Name = "Prateek" Age = 26 print("your name & age are", Name + Age)Find errors in the following code fragment.
A = 3 S = A + 10 A = "New" Q = A / 10Predict the output:
x, y = 20, 60 y, x, y = x, y - 10, x + 10 print (x, y)Predict the output:
a, b = 12, 13 c, b = a*2, a/2 print (a, b, c)