Swap two values

Swap two values with third variable

x = int(input("Enter a value for x: "))
y = int(input("Enter a value for y: "))

print("Before swapping:\nX: " + str(x) + "\nY: " + str(y))

# swapping numbers
temp = x
x = y
y = temp

print("After swapping:\nX: " + str(x) + "\nY: " + str(y))
Output
Enter a value for x: 100
Enter a value for y: 200
Before swapping:
X: 100
Y: 200
After swapping:
X: 200
Y: 100

Swap two values without third variable

x = int(input("Enter a value for x: "))
y = int(input("Enter a value for y: "))

print("Before swapping:\nX: " + str(x) + "\nY: " + str(y))

# swapping numbers
x = x + y
y = x - y
x = x - y

print("After swapping:\nX: " + str(x) + "\nY: " + str(y))
Output
Enter a value for x: 4
Enter a value for y: 8
Before swapping:
X: 4
Y: 8
After swapping:
X: 8
Y: 4