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

Alex Diaz
Alex Diaz
4,930 Points

Not sure what's wrong with my code

I've already researched this challenge and a mod gave what the correct output should be, I ran my code in workspaces and got exactly what she had in her code. Thank you!

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

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

1 Answer

You only need to print one newline.

print("\n", end="\n")  # This is WRONG. It prints two newlines (the first is the printing value the second is the `end`)

print("", end="\n")  # This code is CORRECT. It prints only one newline.

# Note that this code below is the same as the one above (it prints exactly one newline):

print()

I hope this helps. ~Alex

Alex Diaz
Alex Diaz
4,930 Points

Yep, that fixed it, thank you! :D