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

Where am I wrong?

I "Check Work"... It's a success. But when I check it again, I get a "Bummer" message. Same code, nothing changed.

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

1 Answer

Hi Mankwe, I assume that you're stuck on the second task. What it wants you to do is:

  1. loop through the list
  2. check if the continent's first letter is "A"
  3. print that continent.

Here's the answer:

continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here

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

Hi Jassim, a thousand thanks for your reply. It works.

But should you find time again, here's something I do not understand about this code:

  1. if continent[0] == "A": ------------ This says that if the index zero of the list is equal to "A". : But index zero of the list is "Asia", not "A". So why does the code pick the first letter : instead of "Asia"?

I hope my question makes sense.

Thanks.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Mankwe Mokgabudi! I think you're misreading that :smiley: Just like we can get an element from a list using an index, we can do the same thing for a string. For instance:

student = "Mankwe"
print(student[2])

Output:

n

Because "n" is found at the index of 2 in the string "Mankwe"

As we cycle through the list continents, we pull out each individual continent and assign it to the variable continent. This is where it might be more helpful to think of the singular continent vs the plural continents. The first iteration, continent will be equal to the string "Asia". Then we take a look at the 0 index of "Asia" which is "A". The next iteration, continent will be equal to 'South America'. The index 0 of that string is "S" so it doesn't get printed. And so forth until we've run out of continents to check and print.

It might be more helpful to think of it this way:

for individual_continent in continents:
    if individual_continent[0] == "A":

Hope this helps! :sparkles: