Complete the Python programming snippet given below based on the information provided here.
a = int(input("Enter variable a:"))
b = int(input("Enter variable b:"))
print(a,b)
a = a + b
# enter your solution here
# end of your code
print(a,b)
Two values are entered and stored into
the variables a and b. The values of the variables are then
switched so that the variable b now contains the original value of
the variable a and the variable a now contains the original value
of the variable b. Print the results.
Hint in deciphering the user
request:
If the user enters a value of 6 which
is then assigned to the variable a and then the user enters a value
of 10 which is then assigned to the variable b, when this problem
is finished, what value will be stored in the variable a? What
value will be stored in the variable b?
The number 16 would be stored in a and 10 for B.
CODE:
a=int(input("Enter variable a:"));
b=int(input("Enter variable a:"));
print(a,b); #the original values of a and b
a=a+b;
a=a-b;
swap=a;
a=b;
b=swap;
print(a,b); # after swapping a contain b's original value and b
contain a's original value
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.