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

Hey guys, I'm looking for help with indexing in python. I'm supposed to print out continents that start with A only.

There are 7 continents and only those beginning with A are wanted.

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]

print("Continents:")
for continent in continents:
    print("* " + continent)
a = continents[0]
b = continents[3]
c = continents[5]
d = continents[6]
A = a + b + c + d
print("Suggested continents:", A)

1 Answer

Steven Parker
Steven Parker
231,248 Points

You don't want to tie your code to specific indexes, what if the list gets changed later?

But your original loop will do the job, with just a conditional statement added to control the "print". So put an "if" statement before the "print" with an expression that compares the first character of the current continent with the letter "A".

Thank you let me try and do that.

Steven Parker
Steven Parker
231,248 Points

Panashe Mutsikwi — Write again if you need more help, and otherwise you can mark the question solved by choosing a "best answer".
Happy coding!