Skip to content
Home » Python program to swap the given numbers

Python program to swap the given numbers

Below is the program to swap the given two numbers

# swap two numbers
a=int(input("Enter a number:"))
b=int(input("Enter another number:"))
print("Original value of a is ",a,"and b is ",b)
temp=a
a=b
b=temp
print("Numbers after swapping")
print("Now a is ",a,"b is ",b)

Output:

Enter a number:2
Enter another number:7
Original value of a is 2 and b is 7
Numbers after swapping
Now a is 7 b is 2