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 trialBrendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsWhat am I doing wrong in this challenge?
My code:
TILES = ('-', ' ', '-', ' ', '-', '||',
'_', '|', '_', '|', '_', '|', '||',
'&', ' ', '_', ' ', '||',
' ', ' ', ' ', '^', ' ', '||'
)
for tile in TILES:
if tile == "||":
line_end = "\n"
else:
line_end = ""
print(tile, end=line_end)
It makes this output:
- - -||
_|_|_|||
& _ ||
^ ||
3 Answers
Jennifer Nordell
Treehouse TeacherHi there! For anyone reading about the answer to this challenge, I was able to get it done, but the output was slightly different than what I expected. It's not enough to begin a new line and start printing out the tiles again. But rather there should be a completely blank line between the output lines. Here's a sample of failing output and a sample of correct output.
Correct output:
- - -
_|_|_|
& _
^
Incorrect output:
- - -
_|_|_|
& _
^
Hope this helps someone!
Kenneth Love
Treehouse Guest TeacherThanks for bringing this up! Added a bit more to the description (literally, a bit. Y'all gon' be disappointed :D) that should make it clearer what the challenge is expecting. If anyone has further suggestions, let me know.
Philip Gales
15,193 PointsAccording to the python documentation, the print function will print an object (string like tile) followed by the end argument.
print(tile, end=line_end)
This code will first print the tile object and then whatever the line_end variable is. This is generally fine, but going back to the instructions, we are told otherwise.
Print each item on the same line unless the item is a double pipe (||). In that case, print a new line (\n).
Notice they emphasized 'unless' in the instructions. At first one would interpret this as creating an if-statement to handle a new line or not. This idea is reinforced by the last line about using the end argument to control print(). But, after reading the instructions again, you'll notice they only want a new line printed and not the item when the double pipe is used.
Jennifer Nordell got the idea when she tried replacing the tile object with an empty string in her first print function. I suspect this does not work as it overcomplicates the solution.
P.S. Can Michael Hulet point me in the direction of the community guidelines?
Jennifer Nordell
Treehouse TeacherYes, it was this that I was misinterpreting:
Print each item on the same line unless the item is a double pipe (||). In that case, print a new line (\n).
I thought that because print's default ending was a new line we should replace the double pipe and then let the output start immediately on the next line using the ending of a new line character. Because if we replace it, and tell it that the end is the new line character, then it does still print out a new line character. It just doesn't print out two of them as say this code would:
print("hello")
print("\n")
print("world")
And of course, this will print out two blank lines between "hello" and "world". Because the print function prints a new line and contains another new line character by default. In my opinion, my output does match what they describe. I did print out a single new line character unless it was a pipe. But that was, of course, my misinterpretation.
I feel like the instructions here are still a bit ambiguous
Philip Gales
15,193 PointsYes. Very ambiguous.
Chris Freeman
Treehouse Moderator 68,457 PointsNice thread. Tagging Kenneth Love to review challenge wording to remove ambiguity. On Collections – Line Endings challenge
Steven Parker
231,275 PointsFollow-up: the challenge functionality has been changed.
Wording aside, the function of this challenge was rather non-intuitive. It has been changed now so that blank lines are no longer required or accepted.
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherI wish I could upvote a question right now. I have no idea. I've been stuck on this challenge for a while and just hoping that I could make my way through it. And you and I have very similar code, but slightly different output. The difference being that you're printing the tile even when it's it's the
||
. I do not. That being said, my code still will not pass the challenge.Here's my current code (which doesn't pass):
# Removed as it was too close to the actual solution
And here's my output:
I believe my output may be closer to what they're expecting, but I really am not sure. It'd be nice to know what the expected output looks like, in my opinion. I sincerely hope someone has the answer to this question because I'm out of ideas
Actually, I have one more. Michael Hulet do you happen to know what we're missing here?