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 trialEmily Strobl
5,429 Pointshelp me part 3
i tried everything to indext just the continents that begin with A but im still getting all of the continents
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
print ('continents'[0])
print ('continents:')
for continent in continents:
print('* ' + continent)
1 Answer
Cameron S
20,537 PointsYou need to use the slice to get the first letter of each list item within a if
statement to make sure the returned value is equal to 'A'. That if
statements should be inside the for loop
you already have.
For example:
# list of continents
>>> continents = [
... 'Asia',
... 'South America',
... 'North America',
... 'Africa',
... 'Europe',
... 'Antarctica',
... 'Australia',
... ]
>>> for continent in continents:
# if the first index (first letter) of each item within
# the list is equal to "A"
... if continent[0] == "A":
... print(continent)
...
Asia
Africa
Antarctica
Australia
>>>
Also note a bug within your code:
print('continents'[0])
# this will return the first index of the string 'continents not the list.
# so you would get back the letter 'c' instead of a continent from the list