Programming Examples

Python program to read 3 numbers in 3variables and swap first two variables with the sums of first and second


Write a program to read three numbers in three variables and swap first two variables with the sums of first and second ,second and third number respectively.

Solution

n1=int(input("Enter number 1 : "))
n2=int(input("Enter number 2 : "))
n3=int(input("Enter number 3 : "))
print("Original Number : ",n1,n2,n3)
n1,n2,n3=(n1+n2),(n2+n3),(n3+n1)
print("After Swapping : ",n1,n2,n3)
Output

Enter number 1 : 4

Enter number 2 : 3

Enter number 3 : 5

Original Number :  4 3 5

After Swapping :  7 8 9

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad