Sameer Zahid5,967 Points
Code 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?
In 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.
So 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
ryanostenPHP Development Techdegree Student 26,448 Points
Hey 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"
line_end = ""