I'm really confused. I've been working on the code below (and image attached)-- I keep getting a syntax error for the line print myList[i],' ',
I think it has to do with parenthesis but i'm not sure. Any help is appreciated!
def SwapFirstAndLast(list):
temp = list[len(list)-1]
list[len(list)-1] = list[0]
list[0] = temp
def ReplaceEvensWithZeros(list):
for i in range(len(list)):
if(list[i] % 2 == 0):
list[i] = 0
#Initializes a list with ten random integers
import random
myList=[]
for i in range(10):
myList.append(random.randrange(1,101,1))
#- every element at an even index
for i in range(0, len(myList), 2):
print myList[i],' ',
#- every even element
print
for i in range(len(myList)):
if myList[i] % 2 == 0:
print myList[i],' ',
#- all elements in reverse order
print
print myList[::-1]
#- only the first and last element.
print myList[-1:], ' ', myList[:1]