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

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

Please help me with this. Thank you. still stuck here!!!

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

I don't get it yet loll

3 Answers

So we know we can access the string using index. the for loop will take all these continents one by one and iterate it. When the variable(continent) will have first continent(Asia), it will go inside the loop and check if the continent name starts from "A". if it dose it will print the name of the continent else it will go back to the for loop and go on with the second continent and again check if that continent starts with "A". for loop will take all the continents one by one and if statement will check if the continent starts with letter "A". if continent[0]=="A" will check the first alphabet in the continent and prints if that starts with letter "A".

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

Let me know if you understood!

Thank you

Use an if statement and use the fact that you can access the first element of a string just like a list, i.e. indexing by 0 str[0] for example. Also remove this line: print(continents) since it's not needed.

Let me know if you understood.