user11319005
user11319005

Reputation:

Why is my for-loop printing on every other line and not every line?

My function is:

def draw_map():
    for row in list:
        for tile in row:
            print(tile, end=' ')
        print('\n')

Output is:

                  _ _ _       o

                /       \   O

                \       /

                  ‾ ‾ ‾

Output should be:

                  _ _ _       o
                /       \   O
                \       /
                  ‾ ‾ ‾

Edit: Removing print('\n') makes the output:

                      _ _ _       o                             /\   O                               \       /          ‾ ‾ ‾

So why is the one \n making it print on every other line?

Upvotes: 1

Views: 138

Answers (1)

Nathan
Nathan

Reputation: 10306

print has end="\n" by default, so doing print("\n") prints two newlines. I think you just mean to do print().

Upvotes: 8

Related Questions