Here's the problem:
Given a list of integers, make it so that the first and last integers are added and that result will be the first integer of the new list, the second and second-to-last integers are added and the result will be the second integer of that new list and so on. if your list is odd, leave the central number in the original list.
Two problems I'm having. I don't know how to get my code to keep iterating while taking the first and last values, adding it to the new list, and working it's way to the middle. Also how do I get it to iterate and stop at a middle value if it's odd?
Here's my code so far:
myList = [1,2,3,4,5,6]
newList = []
def switch(myList):
for i in range(len(myList)):
if len(myList) % 2 == 0:
firstPart = newList+myList[0:+1]
secondPart = myList[len(myList)-1:len(myList)+1]
thirdPart = firstPart + secondPart
return thirdPart
else:
if len(myList) % 2 == 1: