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

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 68,457 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 68,457 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

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 68,457 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()

Thank you!!