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 trialStanley Nkosi
4,233 PointsIterating over Range -Task 1 of 1 How do you append my_list ? Stanley Nkosi
The body of the for loop should append the current value to the provided list called my_list.append(val)
my_list = []
for i in range(0,10,1):
my_list.append(val):
print(i)
4 Answers
Stanley Nkosi
4,233 PointsThank you Steve.
Steven Parker
231,271 PointsHere's a few hints:
- each line of the body of the loop must be indented more than the "for" line
- the "append" line should not end in a colon
- where does the "val" come from that you are appending? It's not defined in this code
Stanley Nkosi
4,233 PointsHi Steve, Thank you for the answer.I have indented the body.I have removed the semi-colon. Now,when I recheck it says,"Whoops it looks like my_list contains incorrect values or values are missing. The 'val' comes from the instruction that says,"To append a value to a list use syntax my_list.append(val).
Steven Parker
231,271 PointsWhen I run it with the other fixes applied, I get: "Bummer: NameError: name 'val' is not defined".
The instruction example is intended to be generic, they are using the term "val" to represent the variable that will contain the value you want to append. You wouldn't use the actual term "val" unless you chose that as your loop variable name.
Stanley Nkosi
4,233 PointsHi Steve, I have removed "val". When I recheck,I get the bummer that says,"Whoops looks like my_list contains incorrect values or is missing values.
Steven Parker
231,271 PointsYou "removed" it? Did you put something in it's place? (Hint: what is it you want to append?).
If you're still having trouble, repost the whole code in the current state.
Steven Parker
231,271 PointsSteven Parker
231,271 PointsStanley Nkosi — normally you'd choose "best answer" on the answer that helped solve the question!