JackSparow
JackSparow

Reputation: 179

Getting additional empty line at the end of the output

Getting a additional empty line at the end of the output.

n = 3
space_count = n-1
count = 1

while count <= n:
    print(" " * space_count, "#" * count, end = "")
    space_count = space_count - 1
    count += 1

Expected Result:

   #
  ##
 ###

Actual Result:

   #  ## ###

Upvotes: 1

Views: 73

Answers (1)

Batman
Batman

Reputation: 8917

It's because you've specifically told Python that each line should end with an empty string ("") instead of a new line (\n).

Change your print line to:

print(" " * space_count, "#" * count, end = "\n")

This is actually the default behaviour. So you could also just use:

print(" " * space_count, "#" * count)

Upvotes: 3

Related Questions