List manipulation in functions


#1

def my_function(x):
      for i in range(0,len(x)):
         x[i] = x[i] * 2 
      return x
    x=[0,1,2]
    print my_function(range(0, len(x)))

Why does this happen?


#2

What does happen? :wink:


#3

If the exersice is REALLY List manipulation in functions, you should append 9 to the list and return it.


#4

how do you do that exactly?


#5

1st = [1, 2, 3, 4]
def list_extender(lst):
    1st.append(9)
        return 1st

print list_extender(1st)

I have this now and it seems to be giving me troubles...


#6

n = [3, 5, 7]
# Add your function here
def list_extender(lst):
    n.append(9)
return lst


list_extender(n)

now it is this... what am i doing to get these answers???


#7

does anyone know the answer to this part? I have tried everything forever


#8

Sorry for a late answer. Your list lst should be written with L instead of 1.


#9

n = [3, 5, 7]
# Add your function here
def list_extender(lst):
    n.append(9)
return lst


list_extender(n)

now I have this and it still doesnt work


#10

It is an L though. I changed it


#11

  

File "python", line 5
SyntaxError: 'return' outside function

#12

You need to indent your return statement on line 5.


#13

Oops, try again. list_extender([1, 2, 3, 4]) returned [1, 2, 3, 4] instead of [1, 2, 3, 4, 9]


#14

what do I do with this?


#15

I think you need to do lst.append(9)


#16

    n.append(9)

I already did that though it is in my code


#17

oh nevermind. I get it now. Thankyou!


#18

No problem. :slight_smile: Glad you got it.


#19

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.