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 trialMahbubul Haq Bhuiyan
582 PointsWhat's wrong with the code?
Can someone help me with the correct code
continents = ['Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia']
for continent in continents:
print("* " + continent[A] )
2 Answers
Steven Parker
231,269 PointsThe variable "A" was never declared. But you don't need indexing here, because the loop itself gives you each individual item one at a time in "continent":
for continent in continents:
print("* " + continent) # no index needed
Mahbubul Haq Bhuiyan
582 PointsGot it done,thanks mate :)
Mahbubul Haq Bhuiyan
582 PointsMahbubul Haq Bhuiyan
582 PointsI mean the second task of this, where I need to show the continents that starts with A, tried but failed
Steven Parker
231,269 PointsSteven Parker
231,269 PointsOh, that explains the "A". Inside your loop, you could add an "if" statement to control when to execute the "print". Your "if" statement can compare the first letter of the continent name to the letter "A" using an equality comparison ("
==
").The index will be useful in the "if" to get a single letter from the string, and the value 0 (zero) would select the first one.
Steven Parker
231,269 PointsSteven Parker
231,269 PointsMahbubul Haq Bhuiyan — Glad I could help! You can mark the question solved by choosing a "best answer".
And happy coding!