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 Introducing Lists Using Lists Continental

Daron Anderson
Daron Anderson
2,567 Points

Why does it print the answer but say "I have an assertion error?"

Yea, Lol I Don't understand..

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here
for continents in continents:
    print ('* ' + continents)

2 Answers

Hi Daron,

I understand your confusion... ;-)

Your code actually produces the correct result but because you actually use the variable name of the list after the "for" you alter the content of the list. So after your code was running and listing the continents, the continent list then actually only holds the last listed continent. All the other continents are deleted.

You need to change just one letter after the "for" part. Could be anything actually but the most obvious one would be to just use the word "continent" instead of "continents". That way the list stays as it is:

for continent in continents:
    print ('* ' + continent)

Makes sense?

Happy coding!

Nils

PS: You can upvote my post and/or mark as "best answer" (at the bottom of my post) if it helped you. :-)

Sorry, of course you also have to change "continents" to "continent" after the print, I forgot that in my code but just corrected it... ;-)

To make it even clearer you could also use any other name after the for part, like:

for x in continents:
    print ('* ' + x)

Just if you use the same name as the list variable name then you will reassign the list every time the loop runs and thus at the end of the loop the list holds only the last continent.

Daron Anderson
Daron Anderson
2,567 Points

that makes sense that it would say that the values are being altered, I needed to give whatever the name was going to be and insert the list into that new var and have it print the work with the asterisk.