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 trialKars Jansens
5,348 PointsI can't fix this... [Python]
Hey, I got a problem. I realy don't know how to do this. Can some one explain it to me? The question is: Print a bulleted list of each continent from the continents list. Output should look similar to:
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
# Your code here
count = 0
for 'Asia' in continents:
count += 1
for 'South America' in continents:
print('')
else:
del continents[count]
count += 1
4 Answers
Steven Parker
231,248 PointsYou've got the right idea, but there's a few issues, Here's a few hints:
- you don't need a "count" for this challenge
- you only need one loop
- you don't need an "else" or anything after it (particularly no "del"!)
- a loop argument must be a variable name instead a constant (like "
for item in continents:
") - the "print" statement must contain what you want to print
- you can use concatenation (+) to combine a constant string (like
"* "
) with a variable
Steven Parker
231,248 PointsIt looks like your part 2 solution has an extra loop that is checking every letter of the continent. But the challenge instructions only ask you to check the first letter of the continent.
Also, to make your code readable it needs to be formatted with "Markdown". Use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. Or watch this video on code formatting.
Kars Jansens
5,348 Pointscontinents = [ 'Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia', ]
Your code here
for continent in continents: for letter in continent: if letter[0] == "A": print("* " + continent) Hey, I did the first question.. But there is a second question... The problem is that North America and South America are printed... I need to print every continent that's starts with the letter 'A'.
Steven Parker
231,248 PointsSee the comment added to my answer.
Kars Jansens
5,348 PointsI still don't see what is wrong...
Kars Jansens
5,348 PointsI did it!! It took me 2 hours but I did it. :/ Thank you for helping me.
Steven Parker
231,248 PointsKars Jansens — Glad to help. You can mark the question solved by choosing a "best answer".
And happy coding!
Mohan Kholiya
1,102 PointsMohan Kholiya
1,102 Points//Q2: Answer
print("continent:")
for continent in continents:
if continent[0] == "A" :
print("* " + continent )