Dùvida foor loop python


#1

Create a function called double_list that takes a single argument x (which will be a list) and multiplies each element by 2 and returns that list. Use the existing code as a scaffold.

I did this:

n = [3, 5, 7]

def double_list(x):

for i in x(0, len(x)):
x[i] = x[i] * 2

return x

print double_list(n)

And the freaking thing says that “list” object is not callable


#2

your for loop is incorrect:
for i in x(0,len(x)): is throwing the error. you should change it to:
for i in range(0,len(x)):


#3

OK thanks!
it worked!


#4

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