Help me with this

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

Hi @shubhamkswn00
Here is the code that you can refer,

val=eval(input("Enter a list "))
print(“Original List is:”,val)
s=len(val)

if s%2!=0:

s=s-1

for i in range(0,s,2):

val[i],val[i+1]=val[i+1],val[i]

print(“List after swapping :”,val)

Hope it might helps :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.