12. Printing out a list item by item in a function


#1

Hello, I have an "Oops, try again. The body of your function should not contain any references to 'n'" error and I don't understand where the problem is.

def print_list(x):
    for p in range(0, len(x)):
        print(x[p])

#2

Your code is fine, but may not look like what the SCT expects. Did you try iterating the list directly, instead of by index?

for p in x:
    print p

Remember to call your function on the list in n

print_list(n)

#3

Hi @vitalka228 ,

Your function works perfectly. However, as @mtf has noted, your code differs from what Codecademy's submission correctness test (SCT) is expecting.

The default code contained a reference to n[i], and the SCT will reject your code if it still contains such a reference, even if it is not inside your function. A good remedy is to remove this original loop that was given in the default code, if it is still there ...

for i in range(0, len(n)):
    print n[i]

We realize that you were not actually told in the instructions that the original loop had to be removed.


#4

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