Why does it say n should not be used in the body of my function when it isn’t?
Answer
This seems to be an error present in this exercise at the time of writing. If you leave the initial for loop code as it is and write your print_list function after it, it marks your code incorrect even if it is the right solution.
To work around this, delete the initial for loop and the print statement inside of it and try running your code again.
If that doesn’t work, check to make sure you are iterating using x as your list you’re checking and printing values from, and that you are using your function by calling print_list(n) at the end, outside of any functions (unindented).
In this exercise, after running the function print_list(n) in the console I got the values 3,5, and 7 printed individually, but I also got “None” printed on the last line. What does it mean?The program runs smoothly and does not show any error message, is this a Semantic Type of error ?
because that is what return does? returns mean literally that, handing something back
its kind of like when making an exam, lets say the exam has 3 questions (just like the loop has 3 iterations), you can perfectly return the exam to the teacher after having only filled in the answer to the first question. Same with the loop
n = [3, 5, 7]
def print_list(x):
print x
for i in range(0, len(x)):
print x[i]
print_list(n)
The thing is, you’re supposed to keep the for loop INSIDE your function, and when you do that, change all the "n"s in the loop from “n” to “x”. This worked for me, and I had no problems.
I just ran into the same problem here. When you take out the len() function and the associated for loop, a message pops up that says the lesson was modified to use the len() function. To get around this, just create a variable and set it to equal len(whatever item you have in your for loop).
My code looked like this:
n = [3, 5, 7]
def print_list(x):
for item in x:
lenth = len(x)
print item
print_list(n)
This way, there is a len() function in the code to satisfy the requirement for the lesson, but it doesn’t change the output.