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 trialNadia Stoyanova-Lyttle
2,063 PointsIndentationError
I'm stuck with a task to print continents starting with "A":
continents = [ 'Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia', ]
Your code here
print("continents:")
for continent in continents:
if continent[0] == "A":
print("* " + continent)
Could you please help?
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
# Your code here
print("continents:")
for continent in continents:
if continent[0] == 'A':
print('* ' + continent)
2 Answers
Steven Parker
231,236 PointsAs the system said, there's an indentation issue. Otherwise, you have it just right.
Everything inside a loop must be indented more than the "for" line, and then anything controlled by a conditional must be indented more than the "if":
for continent in continents:
if continent[0] == 'A': # indented for loop
print('* ' + continent) # indented more for conditional
Nadia Stoyanova-Lyttle
2,063 PointsThank you so much, Steven! It's the little details that I have found the hardest to make right in my early python steps :-)