🚀 Hurry! Offer Ends In
00 Days
00 Hours
00 Mins
00 Secs
Enroll Now
X
Questions




































Write a program to exchanging values of two variables.

Last Updated : 23 May 2026 Jan 19, Jul 22

Solution:

# Get input from the user
a = int(input("Enter First number: "))
b = int(input("Enter Second number: "))

# Show values before swapping
print("Before swapping a = ", a, "b = ", b)

# Swap the values
a, b = b, a

# Show values after swapping
print("After swapping a = ", a, "b = ", b)

 

OUTPUT:

Enter First number15
Enter Second number24
Before swaping a=  15 b=  24
After swaping a=  24 b=  15

Explanation:

  • Input:

    • a and b are read and converted to integers.
  • Before Swapping:

    • Prints a and b.
  • Swap:

    • a, b = b, a exchanges the values.
  • After Swapping:

    • Prints the swapped values of a and b.
Report an error

Meanwhile you can watch this video

Watch Video
Latest Updates