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 trialMovrard Herard
Courses Plus Student 543 Pointscant figure out index exceptions
ive tried a couple ways to exclude non-A countries but nothing has worked. for example: except continents != (str[0] == "A")
continents = ['Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia']
# Your code here
for continent in continents:
print("* " + continent)
1 Answer
Steven Parker
231,248 PointsIt doesn't look like you've added any code for task 2 yet.
You'll probably want to put an "if" statement between the loop and the print lines, so the print only runs when the correct condition is met.
The challenge included this "HINT: Remember that you can access characters in a string by index". So if you used an index to access the first character you could compare it to a specific one you want to see.
Movrard Herard
Courses Plus Student 543 PointsMovrard Herard
Courses Plus Student 543 PointsThank you for the reply. I have tried using a if statement but may be confused in my understanding of the writing logic. For example in between the loop and print ive written different lines such as
If continents(str[0] == "A"): or even If continents[[0]] == "A":. But its not working for me.
Thanks again
Steven Parker
231,248 PointsSteven Parker
231,248 PointsIt looks like you have the right idea, but several syntax errors:
If continents[[0]] == "A":