Python Program to find swap two numbers without temp variable (Multiplication and Division Method)

Program

a = int(input("Enter the value of a:\n"))
b = int(input("Enter the value of b:\n"))
print("Values before swapping:")
print("a:\t{}\nb:\t{}".format(a,b))
a = a * b
b = a / b
a = a / b
print("Values after swapping:")
print("a:\t{}\nb:\t{}".format(a,b))

Output 1

Enter the value of a:
66
Enter the value of b:
12
Values before swapping:
a:	66
b:	12
Values after swapping:
a:	12
b:	66

Tags: