Write a python program to swap two numbers without using a temporary variable.

 # Input two numbers from user

a = int(input("Enter first number (a): "))

b = int(input("Enter second number (b): "))


print(f"Before swapping: a = {a}, b = {b}")


# Swapping without using a temporary variable

a = a + b

b = a - b

a = a - b


print(f"After swapping: a = {a}, b = {b}")



Output:


Comments