What is wrong with my code? (Modifying an element of a list in a function)


#1



https://www.codecademy.com/courses/python-beginner-nzzVa/2/3?curriculum_id=4f89dab3d788890003000096


. Your code looks a bit off.

Traceback (most recent call last):
File "python", line 6, in
File "python", line 3, in list_function
TypeError: list indices must be integers, not tuple


I expect the program to return the list.


def list_function(x):
    x[1] = x[1] +3
    return x[0,1,2]

n = [3, 5, 7]
print list_function(n)


#2

x is a variable holding the list, so you can just return x


#3

Got it now, thank you!:relaxed:


#4

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