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 trial

Python Python Collections (2016, retired 2019) Dungeon Game Line endings

Peter Tram
PLUS
Peter Tram
Courses Plus Student 6,898 Points

Bummer. Didn't get the right output. Why?

...

mapping.py
TILES = ('-', ' ', '-', ' ', '-', '||',
         '_', '|', '_', '|', '_', '|', '||',
         '&', ' ', '_', ' ', '||',
         ' ', ' ', ' ', '^', ' ', '||'
)

for item in TILES:
    if item != "||":
        print(item, end="")
    else:
        print("\n")

3 Answers

Read this post.

:point_right: 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 :smiley:

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 :grin:

Happy coding! :tada:

:dizzy: ~Alex :dizzy:

The 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.

Darn. Answered at the same time :expressionless:

Lol. This happens all the time with me :monkey:

Upvoted :+1:

Can you give either mwagner or I a Best Answer? Thank you! It will mark your question as "Answered".