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

Indentation error on Continents task

I keep getting an indentation error on this and have tried indenting and unindenting every line and am getting nowhere. Indenting is something i am still unsure how and when to do it. here is what I got so far.

continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
print("Continents:")
for continent in continents:
if continents[0] == "A":
    print("* " +continent)

3 Answers

One more change. With an s continents[0] refers to the first item in continents which is 'Asia'. Without an s continent[0] refers to the first character in continent which is what you want:

for continent in continents:
    if continent[0] == "A":
        print("* " + continent)
Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

The if block needs to be indented under the for loop.

Steven Parker
Steven Parker
229,708 Points

As Chris said, plus the "print" will need to be indented further to keep it controlled by the "if":

for continent in continents:
    if continent[0] == "A":
        print("* " + continent)

Also see Kris(K)'s explanation regarding the conditional expression..