Modifying each item in a list in a function


Why isn't my code returning the right answer? what am I doing wrong?

This error keeps popping up.
Oops, try again. double_list([0, 1]) returned [6, 5, 7] instead of [0, 2]

 n = [3, 5, 7]
def double_list(x):
    for i in range(0, len(x)):
        x[i] = x[i] * 2
        return n
# Don't forget to return your new list!

print double_list(n)


After your for loop you should return x instead of n. Otherwise it's right


Yea I figured it out afterwards thanks! Also the return x was to far indented .


No problemo! :wink: Your hitch was that n is the old list, and x is the updated one.


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