Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Justin Armstrong3,702 Points
Accessing 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, continents, continents, continents]: print("* " + continent)
You're very close. read the instructions again, don't do things that u didn't been asked to do.
Two 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.
continents = [ 'Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia', ]
Your code here
for x in continents: if x == "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