Swap the value between two variable in Python3

 1. Without using a temporary variable

x = float(input("Input the value of x :"))

y = float(input("Input the value of y : "))

x, y = y, x


print("Swap Value of x :", x)

print("Swap Value of y :", y)


2. Using temporary variable:

x = float(input("Input the value of x :"))
y = float(input("Input the value of y : "))

swap = x
x = y
y = swap

print("Swap Value of x :", x)
print("Swap Value of y :", y)
Next Post Previous Post
No Comment
Add Comment
comment url