-1

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!

1

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]
falsetru
  • 357,413
  • 63
  • 732
  • 636

1 Answers1

-1

Your syntax error should be something like this:

IndentationError: unindent does not match any outer indentation level

It tells you that you are not formatting your code correctly. Python uses indent to struct the code logic. Please follow the rule.

Peiqin
  • 378
  • 4
  • 12