n = [3, 5, 7] for i in range(0, len(n)): print n[i] def print_list(x): for i in range(0, len(n)): print x[i]
We have an array n containing the numbers 3, 5, and 7
It's total length thus is three.
Therefore the range of (0, len(n)) is (0..3)
Because arrays start indexing at 0
When we try to print n
There is nothing to print! You've indexed out of range!
Your array only contains n,n, and n
what do I print then. I am still very confused.
def print_list(x): for i in range(.3, len(n)): print n[i]
could you maybe give me more of a clue. this level makes no sense to me. what does range mean anyway
range()function returns a list of integers, the sequence of which is defined by the arguments passed to it.
(For syntax and examples please look it up in the Codecademy Glossary by clicking the link above.)
And also, to understand more about it, go to this part of the course:
Oh, and please give a link to your course. It would really help us to help you with the problem.
Okay, I've made a big mistake – now that I've checked my own code.
print range(0,3) will result in [0, 1, 2].
I let fight_dragons' reply confused me. So I've deleted my first reply to you. Terribly sorry for making things difficult.
Now let's start fixing your code.
n = [3, 5, 7] for i in range(0, len(n)): #you can remove this code, because it's just an example given to you by the course to help you. print n[i] #delete this too. you don't need it anymore. def print_list(x): #now let's see your code! for i in range(0, len(n)): #this is your problem. it should be len(x) instead of len(n) because the argument of this function is x. print x[i] print_list(n) #I've added this code for you to check if our code is correct.
Check the course's "Stuck? Get a hint!". It should be this simple!!!
thanks so much. all I really had to do was delete the example and It never said that in the instructions. finished it now anyway. thanks for the help
Terribly sorry for wasting your time with my stupid answers!
But hey, I'm glad you sorted this up.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.