Python Introducing Lists Using Lists Continental

Daron Anderson
Daron Anderson
1,965 Points

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

Yea, Lol I Don't understand..
continents = [
    'South America',
    'North America',
# Your code here
for continents in continents:
    print ('* ' + continents)

2 Answers

Nils Kriedner
Nils Kriedner
17,068 Points

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!


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

Nils Kriedner
Nils Kriedner
17,068 Points

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
1,965 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.