KnowledgeBoat Logo
|

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
  • x is initialized to 40.
  • y is set to x + 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.
  • x is set to 20.
  • y is set to y + 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