Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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,730 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 68,423 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!!!