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/ Explanation:
Enter number 1 : 4
Enter number 2 : 3
Enter number 3 : 5
Original Number : 4 3 5
After Swapping : 7 8 9