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 2021 CCC Practice Test Hindi Python Programming Tutorials 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 Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz