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 trialjames mchugh
6,234 PointsIt says I have 2 errors
I'm trying to list all the continents that start with A. I tried to get them out of the list by their order.
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
for continent in continents:
print("* " + continent)
print(continent[0, 3, 5, 6])
1 Answer
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsIn the right-hand panel, it shows the output of the tests. There's one part that gives us an important clue:
line 14, in
TypeError: string indices must be integers
This is line 14:
print(continent[0, 3, 5, 6])
When you started your for
loop, you're interating through the continents
list, which is a list of strings, and giving each string the local name continent
:
for continent in continents:
So continent
here is the string, not the list (which is continents
plural). Also, python doesn't let you access a subset of the list or string in the way you're doing it continent[0, 3, 5, 6]
.
At any rate, the strategy you're taking here is trying to print out the specific items at specific indices that start with "A". What you really need to do for this challenge is to right code that checks if the first letter is "A" inside the loop. We need your code to work in a way that your part of the code would still work even if there was a different list that had continents starting with "A" in a different order.
Let me know if you have more questions.
james mchugh
6,234 Pointsjames mchugh
6,234 PointsThanks Brendan. I took a break for a few months, so it seems like I need to do some reviewing.