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 don't know how I should go about this question

The question is asking to only print continents with the letter A, how should I go about this

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

hi bro you need to add if statement to check if A in continent before the print line

10 Answers

Steven Parker
Steven Parker
231,275 Points

As Basel suggested, an "if" statement to control when to print would do it. For the conditional test, you can isolate the first character of the "continent" using indexing (square brackets) and then compare it to the letter "A".

Update: You won't need brackets around the 'A'. The brackets would be used for indexing "continent", to select the first character. You may want to revisit the indexing video from the previous stage.

I tried that and I received an invalid syntax on the equal sign

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

One "=" is an assignment operator, you want a comparison ("==") here.

Would this work if continent = ['A']:

So hard brackets around continent

I reviewed the video and I still don't seem to understand how to do it, I was wondering if you could explain to me how to solve this challenge

Steven Parker
Steven Parker
231,275 Points

In the video examples, where are brackets placed to do indexing? And what goes inside the brackets?

You would put the brackets after continents, and the number from the zero based indexing

would this work if I put this above the code from the first step if continents[0] = A:

Steven Parker
Steven Parker
231,275 Points

You can find out quicker by trying it in the challenge! But you want to use the indexing on "continent" (singular), and it looks like you need to put the quotes back around the "A".

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

continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here

for continent in continents:
    if continent[0] = 'A' 
    print("* " + continent)
Steven Parker
Steven Parker
231,275 Points

Getting closer, you need a colon (:) at the end if the "if" line, and the "print" line needs to be indented one more level.

ok thank you so much for your help

Falah Sadiq This really helped was stuck on this for 4 hours. I watched the indexing video 4X's but missed this I saw it used in a string but didn't know it could work with a list. Steven Parker thanks for walking through this.