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


You can understand by Watching video :-



Answer :-

a = int(input("enter 1st number = "))
b = int(input("enter 2nd number = "))
c = int(input("enter 3rd number = "))
a , b = a + b , b + c
print(a,b,c)

Output :-

enter 1st number = 1
enter 2nd number = 2
enter 3rd number = 3
3 5 3

>>> 

enter 1st number = 9
enter 2nd number = 8
enter 3rd number = 7
17 15 7

>>>

7 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. We need to swap only first 2 variable so we should not change c

    ReplyDelete
  2. Please write this program without using multiple assignment...

    ReplyDelete
    Replies
    1. a = int(input("enter 1st number = "))
      b = int(input("enter 2nd number = "))
      c = int(input("enter 3rd number = "))
      a = a + b
      b = b + c
      print(a,b,c)

      Delete
  3. i think there should be
    b=a+b
    a=b+c

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post