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 trialMohammed Saleh
Python Development Techdegree Student 2,989 Pointscan't pass task 2 of continental..
Here is my code..
for continent in continents:
print(" * " + continent)
if continent [0,3,5,6] == "A":
print(continent)
what is wrong. thanks in advanced
7 Answers
Chris Freeman
Treehouse Moderator 68,454 PointsHey Mohammed Saleh, you’re close.
The loop variable continent
is a string. You need to check the first character to se if it’s an “A”. Try:
if continent[0]...
Your current code is not syntactically correct. Since continent
is a string. The only available option is a single character using [0]
or other valid index; or to use a sting slice
Post back if you need more help. Good luck!!!
Mohammed Saleh
Python Development Techdegree Student 2,989 Pointswill snap a picture.
Mohammed Saleh
Python Development Techdegree Student 2,989 Pointsfor continent in continents:
print(" * " + continent)
if continent [0] == "A":
print(continent)
the error: Bummer: AssertionError: 'South America' unexpectedly found in '* Asia\n * South America\n * North America\n * Africa\n * Europe\n * Antarctica\n * Australia\nAustralia' : Whoops! I found a country that didn't start with A in your output
[MOD: added ```python formatting -cf]
Chris Freeman
Treehouse Moderator 68,454 PointsWhat you have is:
for continent in continents:
print(" * " + continent)
if continent [0] == "A":
print(continent)
What you need is of the form
for continent in continents:
if ...
print(...
Chris Freeman
Treehouse Moderator 68,454 Pointsfor continent in continents:
if continent[0] == "A":
# ^ no space before bracket
print(" * " + continent)
Mohammed Saleh
Python Development Techdegree Student 2,989 Pointscan you just show me the answer, I'm trying all the ways but I don't know what I'm doing wrong. thanks.
Mohammed Saleh
Python Development Techdegree Student 2,989 PointsI appreciate your help..to be clear the challenge consists of two tasks, first task it requires us to print the continents with * before each one, which we can do it by ... for continent in continents: print ("* " + continent)
then it asks us to print the continents that starts with A only, without changing the code from task 1. so should I code under : for continent in continents: print ("* " + continent)
Chris Freeman
Treehouse Moderator 68,454 PointsThe code will not pass if the original code from task 1 is left in place unaltered.
In looking at this challenge I don’t see instructions regarding “without changing code from task 1”
Are you running a different challenge?
Mohammed Saleh
Python Development Techdegree Student 2,989 PointsImportant: In each task of this code challenge, the code you write should be added to the code from the previous task..
anyway I altered the code and it worked, thanks so much you were really helpful.
Chris Freeman
Treehouse Moderator 68,454 PointsIn this case, “added to” means “merged with”. If the code must not be changed in a subsequent task, the wording will more explicit.
Great you’ve made it through!
Chris Freeman
Treehouse Moderator 68,454 PointsI answer many of the forum questions from my phone. The warning you quote doesn’t show up on small screens. Sorry for not seeing that.
Mohammed Saleh
Python Development Techdegree Student 2,989 PointsMohammed Saleh
Python Development Techdegree Student 2,989 Pointsthanks but it didn't work for me
Chris Freeman
Treehouse Moderator 68,454 PointsChris Freeman
Treehouse Moderator 68,454 PointsCan you show what you’ve tried and the error you get?