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

index

I can't solve the second part of the challenge when it is asking to print the continents with the initial "A" . Can anybody please help? Thank you!

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

5 Answers

Steven Parker
Steven Parker
231,275 Points

You need to add an "if" statement to control when the "print" is done. Give it a conditional expression comparing the first character of "continent" to the letter "A".

You can isolate a character in a string using an index (value in brackets).

Steven Parker
Steven Parker
231,275 Points

It's impossible to check the indentation without Markdown formatting (as I used below), but if your indentation is already correct it looks like you're only missing the colon at the end of the "if" line:

for continent in continents:
    if continent[0] == "A":      # <-- colon added
        print("* " + continent)

So sorry Steven I'm sure your answer is very clear but i can't figure out the solution.

Steven Parker
Steven Parker
231,275 Points

Try adding an "if" statement using the hints given. If you still have trouble, show the new version.

I'm confused on why this works.. in the if statement you put ( if continent[0] == "A": ) so wouldn't the computer only check and print the location of continent[0] which is Asia instead of printing out the other continents? I hope this made sense.

So Steven I've been trying lots of things maybe the less embarrassing version i wrote is: for continent in continents : if continent[0] == "A" print("* " + continent) And obviously is wrong.

Wow ! Thank you so much Steven, finally it's working. I appreciate so much the way you helped me out!

And Thank you Steven for the Markdown formatting link!