Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Introducing Lists Using Lists Continental

Praise Mupani
Praise Mupani
1,811 Points

Why I am getting an AssertionError on this code ?

I am getting an Assertion Error on this code. Can you please help me out?

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code herecontinent = 0
for x in range(0,2) :
    print("* ",continents[x])

3 Answers

Praise Mupani
Praise Mupani
1,811 Points

Thanks this finally did the trick continents = [ 'Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia', ]

Your code here

for cont in continents : print("* " + cont)

Steven Parker
Steven Parker
210,147 Points

The instructions ask you to print a list showing each continent, but this code will print only the first 2.

Hint: instead of using "range", this might be a good opportunity to use the list variable itself to control the loop.

Also be aware that code added to a comment line will be ignored (but isn't needed in this case).

Steven Parker
Steven Parker
210,147 Points

Note that the "should look similar to" example is just to illustrate the formatting and not intended to be the complete result set.

Praise Mupani
Praise Mupani
1,811 Points

Thanks, Steven may I am getting it all wrong, first, i did the below

for continent in continents : print("*", continent)

and I got the same Assertion error. Then looked on top of the question and I saw the required result as ,

  • Asia
  • South America that is why I used range to print only two elements of the list
Steven Parker
Steven Parker
210,147 Points

This should have been correct for task 1 (always use Markdown formatting when posting code):

for continent in continents:
    print("*", continent)