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 trialPeter Tram
Courses Plus Student 6,898 PointsBummer. Didn't get the right output. Why?
...
TILES = ('-', ' ', '-', ' ', '-', '||',
'_', '|', '_', '|', '_', '|', '||',
'&', ' ', '_', ' ', '||',
' ', ' ', ' ', '^', ' ', '||'
)
for item in TILES:
if item != "||":
print(item, end="")
else:
print("\n")
3 Answers
Alexander Davison
65,469 PointsRead this post.
Your program is printing two newlines when you call print('\n')
since print
automatically prints a newline and you are telling it to print another newline in the string.
This might be confusing, but the answer is simple: By default, the print
function prints a newline. So, when you pass in a newline, it prints that newline and the bonus newline the print
function prints out anyway.
Replace print('\n')
with print('')
and you'll be good to go
Pro tip: In Python, people use print('')
so often that Python lets you pass in nothing, so print()
will do the same thing.
I hope this helps
Happy coding!
~Alex
Mike Wagner
23,559 PointsThe print function in Python 3 defaults to print('', end='\n')
so, essentially you are telling it to print 2 new lines instead of 1. You can remove all arguments, passing only print()
itself or, if you wish to be more explicit, you can keep your existing print statement but change the end
argument to match your other print call.
Alexander Davison
65,469 PointsDarn. Answered at the same time
Lol. This happens all the time with me
Upvoted
Alexander Davison
65,469 PointsCan you give either mwagner or I a Best Answer? Thank you! It will mark your question as "Answered".