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

Ali Dahud
Ali Dahud
3,459 Points

what's wrong with my code?

I'd like you to now only print continents that begin with the letter "A".

HINT: Remember that you can access characters in a string by index Bummer! : Whoops! I found a country that didn't start with A in your output

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

for continent in continents:
    for letter in continent:

        if letter[0]=='A':
            print(continent)

9 Answers

Daniel Boisselle
seal-mask
.a{fill-rule:evenodd;}techdegree
Daniel Boisselle
Front End Web Development Techdegree Student 17,438 Points
continents = ['Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia']
# Your code here

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

You just need a simple check seeing if the first character is == "A"

Each value in the continents list will be assigned to the "continent" value in the for loop. From there you can access the first character by indexing it at the 0th index:

continent[0]

Hope this helps! Dan

Still doesn't pass

Bummer: AssertionError: 'South America' unexpectedly found in '* Asia\n* South America\n* North America\n* Africa\n* Europe\n* Antarctica\n* Australia\n* Asia\n* Africa\n* Antarctica\n* Australia' : Whoops! I found a country that didn't start with A in your output
Marcus Edmondson
Marcus Edmondson
9,454 Points

Task 2 wasn't really clear about adding the asterisk in the print statement. It seemed to only ask to print out continents that start with A.

The Print needs to be nested in the if statement. (If you paste that code, make sure you press enter for it to be correctly spaced onto the next line. If you manually tab then it won't compile correctly.)

Same here

Daniel Solution works for me

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

Tricky one as there is one item in the list that begins with A and is not a continent

my_list = [] char = 'A' for item in continents: if item[0] in char: my_list.append(item) else: continue for continent in my_list: print('* ' + continent)

Bobbi Seesz
Bobbi Seesz
2,272 Points

You have to add the 'if' statement to the first code you did, instead of making two separate blocks.

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

Karyna Reut
Karyna Reut
1,611 Points

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

Spent so long doing my code, in the end, it ended up being right in PyCharm, but shows false in Workspace.