Python program for swapping the value of two integers

Here, we will figure out how to swap the estimation of two numbers utilizing the third factor in Python?

in this article, we will figure out how to swap the estimation of two whole numbers (or can be glide)?

The fundamental thought is:

  • Putting away the estimation of one variable (x) in an alternate variable (to be specific impermanent – temp).
  • At that point changing the estimation of x by duplicating the estimation of y.
  • At that point changing the estimation of y by duplicating the estimation of temp.
  • Three basic advances, three straightforward factors and its everything is done.

So here is the code:

x = float(input('ENTER THE VALUE OF X: '))
y = float(input('ENTER THE VALUE OF Y: '))

temp = x
x = y
y = temp

print('X :', x,' Y :', y)

Output:

ENTER THE VALUE OF X: 10
ENTER THE VALUE OF Y: 20
X : 20.0  Y : 10.0

Leave a Comment

error: Alert: Content is protected!!