You are given two integer variables, x and y. You have to swap the values stored in x and y.

Input:
Two numbers x and y separated by a comma.

Output:
Print 5 lines. The first two lines will have values of variables shown before swapping, and the last two lines will have values of variables shown after swapping. The third line will be blank.

----------------------------------------------------------------------
Sample input:
20, 50

Sample output:

x before swapping: 20
y before swapping: 50

x after swapping: 50
y after swapping: 20

Solution

#Take input using input()

#input() takes input in form of the string
in_string=input()

#here extract the two numbers from the string

#we know the values of our interest are separated by comma so we can use split
mylist = in_string.split(',')
#['12','15']
#and now get our values 
#but they are in string so we first make them int
x = int(mylist[0])
y = int(mylist[1])

# SAJAN'S APPROACH

# #print x and y before swapping
# print('x before swapping: {0}'.format(x))
# print('y before swapping: {0}'.format(y))

# #Writing your swapping code here
# z = x
# x = y
# y = z
# print()
# #print x and y after swapping
# print('x after swapping: {0}'.format(x))
# print('y after swapping: {0}'.format(y))


#without making a new Variable
# print x and y before swapping
print('x before swapping: {0}'.format(x))
print('y before swapping: {0}'.format(y))
#Writing your swapping code here
x=x+y
y=x-y
x=x-y
print()
print('x after swapping: {0}'.format(x))
print('y after swapping: {0}'.format(y))
teststep banner