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

Asif Choudhury
Asif Choudhury
2,086 Points

My Python IDLE is giving right answer, but I am failing the challenge

When I test my code in my computer's IDLE, it gives the result, but for reason unknown to me, I am failing the test.

Thanks a bunch for your time!

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

for i in TILES:
    if (i=='||'):
        print('\n')
    else:
        print(i,end='')

2 Answers

Steven Parker
Steven Parker
231,269 Points

Remember how the print() function works.

Without using the end option, the print() function will add a new line to your output by default. So to print just a new line, you can write print(''). Printing a newline character explicitly will cause two new lines to be output.

Luke Flanagan
Luke Flanagan
5,752 Points

This is a Lifesaver, the wording on the question seems very confusing because it mentions the "\n" which you in fact should not be using

Steven Parker
Steven Parker
231,269 Points

I agree that is a bit confusing, but another way you could output a single newline is like this:

        print('\n', end='')
Asif Choudhury
Asif Choudhury
2,086 Points

Thanks Steven Parker for your explanation; it certainly helped.