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 trialAizah Sadiq
2,435 PointsI don't know how I should go about this question
The question is asking to only print continents with the letter A, how should I go about this
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
# Your code here
for continent in continents:
print("* " + continent )
10 Answers
Steven Parker
231,269 PointsAs Basel suggested, an "if" statement to control when to print would do it. For the conditional test, you can isolate the first character of the "continent" using indexing (square brackets) and then compare it to the letter "A".
Update: You won't need brackets around the 'A'. The brackets would be used for indexing "continent", to select the first character. You may want to revisit the indexing video from the previous stage.
Aizah Sadiq
2,435 PointsI tried that and I received an invalid syntax on the equal sign
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
# Your code here
for continent in continents:
if continent[0] = 'A':
print("* " + continent)
Steven Parker
231,269 PointsOne "=" is an assignment operator, you want a comparison ("==") here.
Aizah Sadiq
2,435 PointsWould this work if continent = ['A']:
Aizah Sadiq
2,435 PointsSo hard brackets around continent
Aizah Sadiq
2,435 PointsI reviewed the video and I still don't seem to understand how to do it, I was wondering if you could explain to me how to solve this challenge
Steven Parker
231,269 PointsIn the video examples, where are brackets placed to do indexing? And what goes inside the brackets?
Aizah Sadiq
2,435 PointsYou would put the brackets after continents, and the number from the zero based indexing
Aizah Sadiq
2,435 Pointswould this work if I put this above the code from the first step if continents[0] = A:
Steven Parker
231,269 PointsYou can find out quicker by trying it in the challenge! But you want to use the indexing on "continent" (singular), and it looks like you need to put the quotes back around the "A".
Aizah Sadiq
2,435 Pointsfor continent in continents: if continent[0] = 'A' print("* " + continent)
Aizah Sadiq
2,435 Pointscontinents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
# Your code here
for continent in continents:
if continent[0] = 'A'
print("* " + continent)
Steven Parker
231,269 PointsGetting closer, you need a colon (:) at the end if the "if" line, and the "print" line needs to be indented one more level.
Aizah Sadiq
2,435 Pointsok thank you so much for your help
Jerry Avila
5,523 PointsFalah Sadiq This really helped was stuck on this for 4 hours. I watched the indexing video 4X's but missed this I saw it used in a string but didn't know it could work with a list. Steven Parker thanks for walking through this.
Basel Kanaan
4,458 PointsBasel Kanaan
4,458 Pointshi bro you need to add if statement to check if A in continent before the print line