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 trialPanashe Mutsikwi
2,310 PointsHey 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 = [
'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
231,198 PointsYou 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".
Panashe Mutsikwi
2,310 PointsPanashe Mutsikwi
2,310 PointsThank you let me try and do that.
Steven Parker
231,198 PointsSteven Parker
231,198 PointsPanashe Mutsikwi — Write again if you need more help, and otherwise you can mark the question solved by choosing a "best answer".
Happy coding!