Python Python Sequences Sequence Iteration Iterating over Ranges

NameError

ONCE AGAIN i am being asked to do something i am not sure how to do. It was not covered in the video and now i need to do some extra stuff like 'append(val)' whatever that means.

iterating_ranges.py
my_list = []
for i in my_list.append(val):
    print(i)
Tim Oltman
Tim Oltman
7,714 Points

Hi Rigby,

First, you want to iterate over a range. The video Iterating with Ranges covers this.

Second, you have to deal with this append stuff. Luckily, you don't have to do anything fancier than just use the code they gave you.

What really helped me when going these courses was to really slow down, pause the videos, and play around with the examples in the workspace as I went. Anything that the instructor does in the video you should type out in the workspace to see how it works. Change some of the values and see what happens.

Then, with the Challenges, the biggest thing is to follow the directions precisely. Break it down into steps, and try it out in the workspace before submitting your answer.

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 63,109 Points

It is the val reference that is causing the
NameError.

# in evaluating the statement 
for i in my_list.append(val):

# The reference
my_list.append(val)
# is evaluated first

Even if val was defined, the append method does not return a value so the for loop would not run. The correct form would be:

for i in my_list:

Post back if you need more help. Good luck!!!