## Python program to swap numbers using temporary variable

### Problem Definition:

In this program, we will learn how to swap two numbers using a temporary variable.

### Logic

First read two numbers form keyboard. Display the numbers before swapping. Then swap the numbers using temporary variable. Then display the swapped numbers.

### Steps (Algorithm):

Step 1: Read two numbers from standard input (keyboard).

Step 2: Print or display original numbers on standard output.

Step 3: In this step we do the actual swapping of number.

Let, num1 be the first variable and num2 be the second variable. First, we store the value of the first variable into a temporary variable. Then the value of the first variable is stored into the second variable. Finally, the value of the temporary variable will be stored in the first variable.

Step 4: Display the swapped numbers.

Number 1 = 20

Number 2 = 30

Number 1 = 30

Number 2 = 20

### Program to swap two numbers using a temporary variable:

`#Python program to swap numbers using temporary variablenum1 = int (input ("Enter the first number: "))num2 = int (input ("Enter the second number: ")) #Print original numberprint ("Before swapping")print ("First number is : ", num1)print ("First number is : ", num2) #Swapping using temporary variabletemp = num1num2 = num1num1 = temp#Print Swapped numberprint ("After swapping") print ("First number is : ", num1)print ("First number is : ", num2) `

### Output:

`Before SwappingEnter the first number: 20Enter the second number: 30After SwappingFirst number is: 30Second number is: 20 `