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 trialCrayton Smith
2,588 PointsIterating 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 = [
'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)
1 Answer
Ravi nandan Singh
30 PointsDid 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)
Crayton Smith
2,588 PointsCrayton Smith
2,588 PointsHere'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