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

Movrard Herard
PLUS
Movrard Herard
Courses Plus Student 543 Points

cant figure out index exceptions

ive tried a couple ways to exclude non-A countries but nothing has worked. for example: except continents != (str[0] == "A")

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

1 Answer

Steven Parker
Steven Parker
231,269 Points

It doesn't look like you've added any code for task 2 yet.

You'll probably want to put an "if" statement between the loop and the print lines, so the print only runs when the correct condition is met.

The challenge included this "HINT: Remember that you can access characters in a string by index". So if you used an index to access the first character you could compare it to a specific one you want to see.

Movrard Herard
Movrard Herard
Courses Plus Student 543 Points

Thank you for the reply. I have tried using a if statement but may be confused in my understanding of the writing logic. For example in between the loop and print ive written different lines such as

If continents(str[0] == "A"): or even If continents[[0]] == "A":. But its not working for me.

Thanks again

Steven Parker
Steven Parker
231,269 Points

It looks like you have the right idea, but several syntax errors:

    If continents[[0]] == "A":
  • the keyword "if" must be lower case
  • index the current item to select the first letter (not the whole list)
  • a single pair of brackets can be used for indexing
  • the inner brackets create a list, but indices must be integers