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

Jordan DeLeon
Jordan DeLeon
1,074 Points

Printing Specific Indexes from a List

To explain what I THINK this code is doing: To begin, it's running a loop through each value in the list "continents", then inside this loop it begins another loop, running through each value(letter) of the string variable "continent". When it cycles through each value of the string, if the first letter (letter[0] of continent) is a capital "A" (which should signify the continent starts with this letter) it should print "continent".

What am I missing??! pounds keyboard

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

4 Answers

John Lack-Wilson
John Lack-Wilson
8,181 Points

Hi Jordan, there is no need for the inner loop you have, i.e. the for letter in continent. The challenge only wants to know if the continent begins with A.

So your code can be simplified like so:

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

You are going through the letters of each continent, but why are you checking if letter[0] == 'a'? letter is the letter itself.

Perhaps this will work?

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

I hope this helps! :grin: :zap: ~Alex

EDIT: There was also a typo (you typed "contient" instead of "continent")!

Jordan DeLeon
Jordan DeLeon
1,074 Points

THAAANK YOOOOU!!! You were both absolutely correct! The solution was simpler than I was making it. #wenttoodeep

Sarah Schaeffer
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Sarah Schaeffer
Data Analysis Techdegree Graduate 11,564 Points

I am typing this exact same thing and the output is reading all the continents that start with "A" including Asia but when I click check work an error comes up and says the continent Asia is not included. I'm not why it is saying this. Please any help will be greatly appreciated! Thank you!