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 trial

Python Introducing Lists Using Lists Continental

Mahbubul Haq Bhuiyan
Mahbubul Haq Bhuiyan
582 Points

What's wrong with the code?

Can someone help me with the correct code

continents.py
continents = ['Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia']
for continent in continents:
    print("* " + continent[A] )

2 Answers

Steven Parker
Steven Parker
231,248 Points

The 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
Mahbubul Haq Bhuiyan
582 Points

I mean the second task of this, where I need to show the continents that starts with A, tried but failed

Steven Parker
Steven Parker
231,248 Points

Oh, 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
Steven Parker
231,248 Points

Mahbubul Haq Bhuiyan — Glad I could help! You can mark the question solved by choosing a "best answer". :wink:

And happy coding!