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 trialJordan DeLeon
1,074 PointsPrinting Specific Indexes from a List
To explain what I THINK this code is doing: To begin, it's running a loop through each value in the list "continents", then inside this loop it begins another loop, running through each value(letter) of the string variable "continent". When it cycles through each value of the string, if the first letter (letter[0] of continent) is a capital "A" (which should signify the continent starts with this letter) it should print "continent".
What am I missing??! pounds keyboard
continents = ['Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia']
# Your code here
for continent in continents:
for letter in continent:
if letter[0] == "A":
print('* ' + continent)
4 Answers
John Lack-Wilson
8,181 PointsHi Jordan, there is no need for the inner loop you have, i.e. the for letter in continent
. The challenge only wants to know if the continent begins with A.
So your code can be simplified like so:
continents = ['Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia']
# Your code here
for continent in continents:
if continent[0] == "A":
print('* ' + continent)
Alexander Davison
65,469 PointsYou are going through the letter
s of each continent, but why are you checking if letter[0] == 'a'
? letter
is the letter itself.
Perhaps this will work?
for continent in continents:
if continent[0] == "A":
print('* ' + continent)
I hope this helps! ~Alex
EDIT: There was also a typo (you typed "contient" instead of "continent")!
Jordan DeLeon
1,074 PointsTHAAANK YOOOOU!!! You were both absolutely correct! The solution was simpler than I was making it. #wenttoodeep
Sarah Schaeffer
Data Analysis Techdegree Graduate 11,564 PointsI am typing this exact same thing and the output is reading all the continents that start with "A" including Asia but when I click check work an error comes up and says the continent Asia is not included. I'm not why it is saying this. Please any help will be greatly appreciated! Thank you!