Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Introducing Lists Using Lists Continental

Daron Anderson
Daron Anderson
2,566 Points

Need insight on how to Print out all the continents that start with an 'A'. the square brackets & parens. confuse me.

"There has to be one and only one obvious way to solve it" Thanks in Advance!!!

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

4 Answers

There is more than one way to do it. You could try startswith() as explained here

Have not tried it in the code challenge but very probably would not work because the challenge explicitly asks for an if-statement + the course teaches accessing the letters in a string with the [].

Daron Anderson
Daron Anderson
2,566 Points

I love the design of your website. @kris Nikolaisen. Is your methodology, "If it works it works?"

Hi Daron,

you need to use an IF statement before the print command in this second task of the challenge.

So... IF the first letter of the word is equal to "A" then - next line - print etc.

To check the first letter you need to index the first letter of the string.

Does that help a bit? Otherwhise I could write more tomorrow, need to go to bed now...

Happy coding!

Nils

Daron Anderson
Daron Anderson
2,566 Points

@Nils Kriedner Where does it ask for the if staement?

HI Daron,

just checked where I saw it and I can't find it.

Either I was halluzinating ;-) or I mixed it up with some other challenge (which is highly likely).

So sorry about claiming something without checking it up again. I was so sure I had read it in that challenges text.

Anyhow, you can definetely solve the challenge with an if statement, that's for sure. I just checked it.

Could you solve it in the meanwhile?

Nils

Daron Anderson
Daron Anderson
2,566 Points

Nils Kriedner I feel it I mix my syntax up with other languages sometimes.