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 trialWilliam Ray Noble
22,190 PointsMust produce only "A" continents.
Hello, I need to print out only the continents which begin with letter A. I've been over the video a couple of times now and cannot seem to locate where he unpacks this functionality. Thanks in advance!
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
print("continents:")
for continent in continents:
print('* ' + continent)
1 Answer
Steven Parker
231,198 PointsThis quiz might draw from more than one video. But here's some hints:
- you can use an "if" statement to control when the "print" runs
- the conditional clause of the "if" can compare the first character to "A"
- you can select a single character from a string using an index in brackets
William Ray Noble
22,190 PointsWilliam Ray Noble
22,190 PointsThanks, I've been back through the lesson on indexing in the previous section, however, I'm still confused. How do you index a string inside of a list?
Steven Parker
231,198 PointsSteven Parker
231,198 PointsYou don't need to do that here since the loop extracts each string as "continent" (singular). So you only need to index that to access the first character (at index 0):
continent[0]