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
>>>
We need to swap only first 2 variable so we should not change c
ReplyDeleteOK.
DeleteThanks❤
ReplyDeleteWelcome : )
DeletePlease write this program without using multiple assignment...
ReplyDeletea = int(input("enter 1st number = "))
Deleteb = int(input("enter 2nd number = "))
c = int(input("enter 3rd number = "))
a = a + b
b = b + c
print(a,b,c)
i think there should be
ReplyDeleteb=a+b
a=b+c
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )