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

It seems my code is reading the first letter of the second word of a string. Tips on how to only read the first word?TIA

Not quite sure how to code to only read the first letter in the entire string

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

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

HI Ashley Chenn

You are on the right track, but the if statement needs to be inside the for loop. With each iteration of the loop, you want to be checking if the continent starts with an "A" and then print out only those. So, your for loop is correct and your if statement is correct (with one exception). You just need to move the if statement up into the for loop and then adjust the name of the variable in the if statement to check the right thing (continent instead of continents). Watch the indentations when you move it. It should look something like this:

for continent in continents:
    if <statement goes here>:
        <block of code for if statement here>

Nice work so far! :) :dizzy: