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

Katrine Guirguis
Katrine Guirguis
2,587 Points

Lists/Continents Python challenge: I need help with task 2

I’m confused about the code for task two....

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

3 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,464 Points

Hey Katrine Guirguis, After Task 1, the for-loop and the print statement output every continent in continents. For Task 2, the challenges is to only print the continents that begin with an A.

One strategy is to use a put the print statement in a code block under a conditional statement, such as an if statement. The condition would be to verify the first character of the continent name begins with an "A".

As a refresher, you can access the first character of a string continent using an index, as in, continent[0] or the method continent.startswith() where the argument is the string you hope to match, as in, startswith(“A”)

Post back if you need more hints. Good luck!!

Chris Freeman
Chris Freeman
Treehouse Moderator 67,464 Points

Sorry, there are two other errors in the code.

  • asterisks were added to the items in the continents list. These need removal
  • the print statement needs to add a space between the asterisk and the continent name
Katrine Guirguis
Katrine Guirguis
2,587 Points

That’s what I thought of, but I kinda need help with the if statement... Also, would we have to use the index string as the challenge says? Thanks!

Chris Freeman
Chris Freeman
Treehouse Moderator 67,464 Points

I’ve expanded my answer above to show more explicit examples on how to access the first character of the variable string continent using an index and with the existing method startswith()