Python Introducing Lists Using Lists Continental

Iterating in Python: string index test failed

In my Workspace, this passes. But when doing it in the Code Challenge, it fails, saying that South America is coming up in the answer.

continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]

for cont in continents:
    if cont[0] == 'A':
        print(cont)

Here's my Workspace response:

treehouse:~/workspace$ python continents.py                        
Asia                                                               
Africa                                                             
Antarctica                                                         
Australia 
continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here
for cont in continents:
    print("* " + cont)

for cont in continents:
    if cont[0] == 'A':
        print(cont)

Here's what the test is telling me in the Code Challenge:

FAIL: test_filtered (main.TestFilteringExecution)

Traceback (most recent call last): File "", line 14, in test_filtered AssertionError: 'South America' unexpectedly found in '* Asia\n* South America\n* North America\n* Africa\n* Europe\n* Antarctica\n* Australia\nAsia\nAfrica\nAntarctica\nAustralia' : Whoops! I found a country that didn't start with A in your output

1 Answer

Ravi nandan Singh
Ravi nandan Singh
30 Points

Did you comment the following code for cont in continents: print("* " + cont)

From what you have shared, it looks like there are 2 loop runnings. First one is printing * <countryName> for all countries. Second one is your answer. I recommend commenting out theese lines

for cont in continents:

# print("* " + cont)