Input a list of numbers and swap elements at the even location with the elements at the odd location

numbers=[3,1,6,7,8,4]
size=len(numbers)
i=0
max=0
while(i<size):
     temp=numbers[i]
     numbers[i]=numbers[i+1]
     numbers[i+1]=temp
     i=i+2
print(numbers)
 
Explanation: we have a list of numbers and we want to interchange the even number locations with odd number locations. we took size of list(number of elements) then initialized variables. then program enters while loop, we are using a variable temp for help in swapping number at locations.
 
temp is  taking value of numbers at locations(index) and number at any index is storing value of next index number. next index number is storing value temp. in this way value at any index is taken temporarily by temp so that it will not lost and it can be assigned to next index position. this is the way of swapping values.
 
counter is incremented by 2 every time, because we are taking next 2 numbers values each time, so we have to move index to next 2 locations after every swapping.