# Lesson 12 range?

#1

https://www.codecademy.com/en/courses/python-beginner-nzzVa/3/1?curriculum_id=4f89dab3d788890003000096#

Alright, brand new to coding and the lesson is getting away from me.

Instructions
Define a function called print_list that has one argument called x.
Inside that function, print out each element one by one. Use the existing code as a scaffold.
Then call your function with the argument n.

So they haven't introduced range or what it does or why it works in this lesson. They just say don't worry about it you'll learn about it later. But I don't understand what it is specifically doing in this code and therefore am very lost.

``````n = [3, 5, 7]

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

So I get that they want us to use the scaffolding provided, but I don't understand what the range function does in this context? I looked up what it does and it makes sense but not in the context of what the lesson is trying to make me achieve if that makes any sense?

Like I would assume that I could just do something like:

``````def print_list(x):
for num in x:
print num``````

Which I think would work? But it won't accept it as correct because it doesn't match the scaffolding of the example code provided and I don't know if it's just because it's not ~their way~ or if what I've written isn't doing what they're asking.

Help please and thank you.

#2

What does len(n) return there?
What does range(0, len(n)) return?
If looping through that value, what values are obtained?
How are those values used?

#3

``````list1 = [1, 2, 3,4,5]
for i in range(0, len(list1)):     // i --->0, 1 ,2 ,3 ,4 {it works as a condition for the loop}``````

range([start], stop )
start: Starting number of the sequence.
stop: Generate numbers up to, but not including this number.

#4

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