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

CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad