Swaping Program in Python


Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of C and D.

This program is a simple Python script that swaps the values of two variables. It prompts the user to input two values, which are then assigned to the variables "c" and "d". The program then swaps the values of these variables and prints out the results.

The program first prompts the user to input two values using the input() function and assigns them to the variables "c" and "d" respectively, using the int() function to convert the input from a string to an integer.

Next, the program uses a temporary variable "a" to store the value of "c" in it and assigns the value of "d" to "c" and value of "a" to "d". Finally, the program uses the print() function to output the results, including the original and swapped values of "c" and "d".


Source Code

c=int(input("Enter the C Values:"))
d=int(input("Enter the D Values:"))
print("Before C Values : ",c)
print("Before D Values : ",d)
a=c
c=d
d=a
print("After C Values:",c)
print("After D Values:",d)

Output

Enter the C Values:10
Enter the D Values:30
Before C Values :  10
Before D Values :  30
After C Values: 30
After D Values: 10


Example Programs