In this method, we can swap values of both the variable in two ways:
P = int( input("Please enter value for P: "))
Q = int( input("Please enter value for Q: "))
# To Swap the values of two variables using Addition and subtraction operator
P = P + Q
Q = P - Q
P = P - Q
print ("The Value of P after swapping: ", P)
print ("The Value of Q after swapping: ", Q)
Please enter value for P: 15
Please enter value for Q: 43
The Value of P after swapping: 43
The Value of Q after swapping: 15
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.