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 trialMankwe Mokgabudi
328 PointsWhere am I wrong?
I "Check Work"... It's a success. But when I check it again, I get a "Bummer" message. Same code, nothing changed.
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
# Your code here
for continent in continents:
print(" * " + continent)
print(continents[0])
print(continents[5])
print(continents[6])
1 Answer
Jassim Alhatem
20,883 PointsHi Mankwe, I assume that you're stuck on the second task. What it wants you to do is:
- loop through the list
- check if the continent's first letter is "A"
- print that continent.
Here's the answer:
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
# Your code here
for continent in continents:
if continent[0] == "A":
print("* " + continent)
Mankwe Mokgabudi
328 PointsMankwe Mokgabudi
328 PointsHi Jassim, a thousand thanks for your reply. It works.
But should you find time again, here's something I do not understand about this code:
I hope my question makes sense.
Thanks.
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherHi there, Mankwe Mokgabudi! I think you're misreading that Just like we can get an element from a list using an index, we can do the same thing for a string. For instance:
Output:
n
Because "n" is found at the index of 2 in the string "Mankwe"
As we cycle through the list
continents
, we pull out each individual continent and assign it to the variablecontinent
. This is where it might be more helpful to think of the singular continent vs the plural continents. The first iteration,continent
will be equal to the string "Asia". Then we take a look at the 0 index of "Asia" which is "A". The next iteration,continent
will be equal to'South America'
. The index 0 of that string is "S" so it doesn't get printed. And so forth until we've run out of continents to check and print.It might be more helpful to think of it this way:
Hope this helps!