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 trialEnrica Fedeli-Jaques
6,773 PointsList exercise not working, but weird
Hi, I get the weirdest message saying that the first item on the list isn't showing when it actually is. I wish I could attache a screenshot! anyone that can figure out why?
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
for continent in [0, 3, 5, 6]:
print("*" + continents[continent])
2 Answers
KRIS NIKOLAISEN
54,971 PointsI think the solution is supposed to work for any list without having to specify indexes. If you had hundreds of entries would you be expected to manually find the index of each item that meets a condition? Or make the code do the work for you?
There is a hint in task 2: Remember that you can access characters in a string by index
For this you can use the syntax continent[0]
to access the first character of continent
. Then compare this to 'A' and if they match print the bulleted continent name. Below is probably the most common solution.
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
for continent in continents:
if continent[0] == "A":
print("*", continent)
KRIS NIKOLAISEN
54,971 PointsYou get (partially) Bummer: AssertionError: '* Asia' not found in '*Asia
Notice the missing space between the bullet and the continent name. Although fixing that will pass the challenge I don't think what you have was intended as a solution. But if it works - why not?
Enrica Fedeli-Jaques
6,773 Pointsoh, you think? I wasn't 100% sure what the test meant, in fact. what do you think was I meant to do? thank you for your answer BTW :) oh, and also, I was at step two, you can't see step one in my code anymore
Enrica Fedeli-Jaques
6,773 PointsEnrica Fedeli-Jaques
6,773 Pointsahah I just went "OH! ... of course!" thank you so much! really appreciated!