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 trialJason Kampf
4,873 PointsAccessing specific characters in a string by index
I’m having difficulty understanding how to do this (part 2 of this quiz). I want to print each continent that begins with “A” in this quiz. I thought if I specified the index and “A” that it would work, but I guess not.
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
for continent in continents:
print("* " + continent[0, "A"])
2 Answers
Steven Parker
231,198 PointsThe index should be just a number. You'll need a separate conditional statement ("if") to compare the indexed character to "A" and control the "print" statement based on the result.
Jason Kampf
4,873 PointsI ended up getting it figured out. Your initial tip helped out, just had to keep working on it. Thanks!
Jason Kampf
4,873 PointsJason Kampf
4,873 PointsThanks for the reply. I've tried the "if" statement with the index of [0] = "A" but it keeps reading only the first continent in the list, rather than the first letter of each continent.
Steven Parker
231,198 PointsSteven Parker
231,198 PointsPlease show the complete code after the changes.