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 trialSameer Zahid
5,967 PointsCode Challenge: Line endings
For the challenge that comes after this video, I've been trying the following code, but it is not getting accepted:
for tile in TILES:
if tile != '||':
print(tile, end='')
else:
print("\n")
It says "Bummer! Didn't get the right output" I've tried it in my editor and I'm getting what I think is the expected result. What am I missing?
Thanks.
3 Answers
Mike Wagner
23,559 PointsIn Python 3, the print function defaults to end="\n"
if no argument is given. The wording for the challenge isn't perfectly clear, but essentially what it wants is a single "\n"
and by printing it you are, instead, giving it 2 of them. Given this behavior you can either call the print function by itself as print()
or you can call it like you do already, but add the same end=''
argument that you use in the other part of the function and you should be golden.
Charles Loder
17,541 PointsSo I'm gonna bump this way up.
My original attempt looked like this:
def print_tiles ():
for tile in TILES:
if tile == "||":
tile = '\n'
print (tile, end='')
Then I followed the advice in this thread:
def print_tiles():
for tile in TILES:
if tile != '||':
print(tile, end='')
else:
print("\n", end='')
And it still fails...
As an aside, I wish that the exercises provided better feedback than "Bummer! Didn't get the right output", perhaps showing us what output created and what it should be, like in unit testing. The preview button just shows a blank page...just a thought
ryanosten
PHP Development Techdegree Student 29,615 PointsHey all - Below is my code. It prints desired output in workspaces (I think). But wont pass the code challenge:
for tile in TILES:
if tile == "||":
line_end = "\n"
else:
line_end = ""
print(tile, end=line_end)
ryanosten
PHP Development Techdegree Student 29,615 Pointssorry I also dont know how to format my code in this forum. I tried three backticks as instructed in markdown tips
Carlos Zuluaga
21,184 PointsYou're printing the double pipe character "||" in your code. Instead of printing it, you must add a new line. Try this:
for tile in TILES:
if tile != "||":
print(tile, end="")
else:
print(end="\n")
Sameer Zahid
5,967 PointsSameer Zahid
5,967 PointsThank you,
I didn't realize it was printing the "\n" twice. Thanks a lot!