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

Still stuck on making a list with items starting with A only

I appreciate the suggestions, but I am just not understanding what I am doing wrong.

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

3 Answers

I got some help and finally got the answer. I had so many suggestions I was just getting very confused. I ultimately needed to delete the print line before if. This really isn't a fair challenge question because the first part of the question requires the print line and then you are supposed to just add to the first part for question two- not have to delete a line.

Since for continent in continents: and if continent[0] == "A": are at the same indentation level, the for loop will print out all the continents, starting with "Asia" and ending with "Australia", before checking the first letter of the continent variable, which is now "Australia". Since "Australia" starts with an "A", the output is

* Asia
* South America
* North America
* Africa
* Europe
* Antarctica
* Australia
*  Australia

The challenge is expecting only the continents starting with "A" to be printed, and only one space between the * and the name of the continent. print("* ",continent) has two spaces after the * since using the , between the arguments adds a space.

The expected output looks like

* Asia
* Africa
* Antarctica
* Australia

Try indenting the if statement and its print statement so that they are within the for loop and removing the first print statement from the for loop.

Hi Jennifer, sorry to see that you felt frustrated, about the outcome, it will become a bit more logical as you move forward in the language, just keep in mind that indentation is important in Python just as semicolons or curly braces are in Javascript, for example.

I can promise you that it will get easier as you go further into the language and you will see that you can create a lot more and build your own projects in python with ease in no time! you'll get to notice syntax errors more easily.

Wish you the best