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

Zhang Dong Zhi
Zhang Dong Zhi
982 Points

what did i do wrong wrong.This question is about continental task 2 of 2

what should be the correct solution of this question.Thank you for helping me out

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

3 Answers

Alan Ayoub
Alan Ayoub
40,294 Points

Hi Zhang,

The for loop is looking for continent in continents and we need to only print the continents that begin with the letter A.

I personally like to start with Pseudo Code:

// If continent starts with the letter A, print continent

For me, there are two things that we need to do:

  1. write an if statement and
  2. reference the first index in the array of continent making it equal to the letter A

When we look for the first letter in any array, we need to reference the first index like so: continent[0]

So in challenge 2, we simply need to add this condition:

    if continent[0] == 'A':

Our final code for this challenge looks like this:

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

I hope that helps!

Hi Zhang, you need to include a conditional statement in your for loop. The statement needs to check if the string starts with the letter 'A'. Read the hint carefully. Good luck!

mark brody
mark brody
1,471 Points

Hi there,

It looks as though the task is testing the ability to pull the first character from a string rather than explicitly call out the index of the list of continents. Imagine you had 1000 items in your list, how would you find all the values that started with an 'A'?

The hint indicates that you can access a string character from the index. Since [0] would be the first character of the string, you can grab this value like this: continent[0]. From there, you can compare that value to the character of 'A'. Here's the code that I used:

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

Hope this helps :)