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 trialJustin Armstrong
3,702 PointsAccessing characters in a string by index
I don't know what to do
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
print("Continents:")
for continent in continents:
print("* " + continent)
for continent in [continents[0], continents[3], continents[5], continents[6]]:
print("* " + continent)
3 Answers
<noob />
17,062 PointsYou're very close. read the instructions again, don't do things that u didn't been asked to do.
Barry Snowe
51,277 PointsTwo things to note:
It looks like you got part one of the challenge right. But you started challenge 2 with another for loop, which is not necessary. Everything should happen in the one for loop you wrote (you just need to revise it to do the new task as well...)
The new task is asking you to be selective as to what you are printing out. When we are selective, we use a decision structure. A for loop is a control structure (i.e. controlling the flow of traffic, so to speak). So what kind of command provides a "decision" structure? As in "I will choose this one thing IF this other thing happens"...?
Also, remember that strings can be treated like "lists" of characters. Think about that when you zero in on that first letter.
Justin Armstrong
3,702 PointsI appreciate the responses, but I still need the answer with a detailed explanation....still confused
<noob />
17,062 Pointscontinents = [ 'Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia', ]
Your code here
for x in continents: if x[0] == "A": print("* " + x) first u loop through the list, then u check if the current element in the list start with the letter A at index 0, if it is u print the current element