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 trialAngela Anders
1,844 PointsNot sure why I'm getting an Assertion Error
My output is correct or at least it looks correct to me, but after the second time it was run, I'm getting a 'Assertion Error.'
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
# Your code here
for continent in [0, 1, 2, 3, 4, 5, 6]:
print("* ", continents[continent])
5 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsIt's not obvious from the output, but comma-separated arguments to print()
are output with a space between then. Since the first item includes a space in "* ", then effectively there are two spaces.
Angela Anders
1,844 PointsSo I assume you just delete the white space and all is good?
Chris Freeman
Treehouse Moderator 68,441 PointsCorrect. You can:
- remove the white space
- add the
sep=''
, argument toprint()
- use a formatted string such as:
f"* {continent}"
-
"* {}
.format(continent)"` "* %s" % continent
Angela Anders
1,844 PointsMy apologies, Chris! I must have clicked it by accident.
Chris Freeman
Treehouse Moderator 68,441 PointsNo worries. Thanks for the upvote!
Angela Anders
1,844 Pointsu"\U0001F44D"
Chris Freeman
Treehouse Moderator 68,441 PointsTreehouse allows markup for "thumbs up". Using ":thumbsup:"
or ":+1:"
==>
Manuel Canario
1,458 PointsI am really lost, this is the way I did it, however, I have not found any instructions on the "f" function uses.
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
# Your code here
for continent in continents:
if continent(0) == 'A':
print("* "+ continent)
Chris Freeman
Treehouse Moderator 68,441 PointsVery close. continent
isnβt a function which is what the parens imply. Use continent[0]
instead.