This Python code swaps 2 Numbers.It obtains two numbers from the user and swaps the numbers using a temporary variable.
Here is source code of the Python code that swaps two numbers.
The program output is also shown below.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
num1 = 75 num2 = 42 print('Before Swapping') print('First Number:{0} '.format(num1)) print('Second Number:{0} '.format(num2)) print('\n') temp = num1; num1 = num2; num2 = temp; print('After Swapping') print('First Number:{0} '.format(num1)) print('Second Number:{0} '.format(num2)) |
Output: