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 trialRyan Aves
2,203 PointsHi all, Do you know why this version of code won't work for showing the continents beginning with "A"?
I tried creating a new list that only pulls "A" continents, using indexed values from the original continents list. That's still returning errors for some reason.
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
# Your code here
continents = continents[0,3,5,6]
print("Continents:")
for continent in continents:
print("* " + continent)
1 Answer
Steven Parker
231,269 PointsYou can't select multiple values from a list that way. But you don't want to modify the list anyway.
Just use an "if" statement so that the "print" only runs when the item begins with "A". The conditional expression can isolate the first letter of a word by using indexing with a value of 0.
Ryan Aves
2,203 PointsRyan Aves
2,203 PointsGotcha, would this work as the "if" statement?
if continents[0] = "A":
print("Continents:") for continent in continents: print("* " + continent)
Steven Parker
231,269 PointsSteven Parker
231,269 PointsAlmost. A single "=" is an assignment operator. The comparison operator is "==".
Also, the "if" statement will need to be placed between the "for" and the "print" lines.