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

Hrithik Sharma
Hrithik Sharma
6,090 Points

How is my program wrong and the task was: I'd like you to now only print continents that begin with the letter "A".

i have done this code and the result is correct but somehow its saying to use "for" loop

continents.py
continents = ['Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia']
# Your code here
for continent in continents:
    print("*", continent)
# This is code of second task
i = 0
while i != len(continents):
    if "A" in continents[i][0]:
        print("*", continents[i])
    i = i + 1    

3 Answers

Wade Williams
Wade Williams
24,476 Points

It appears that you might be getting the wrong answer because you're answering Task 1 and Task 2 at the same time and you're printing out all continents followed by continents that start with "A" and they just want continents that start with "A" in Task 2. You should build off of your answer in Task 1 to complete Task 2.

Here's my solution:

for continent in continents:
    if continent.startswith("A"):
        print("*", continent)

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

What they are asking you to do is extend your existing for loop to check if the continent starts with an 'A'