0

I'm getting an extra new line just after getting input. Help me fix it

while True:
    n = cs50.get_int("Height: ")
    if n > 0 and n < 9:
        break
for i in range(n + 1):
    if n == 0:
        continue
    print(" "*(n-i),end="")
    print("#"*i)

I'm getting this output

Height: 4

   #
  ##
 ###
####
1

Your code is badly formatted, so it is not possible to reproduce your problem easily. Luckily I know Mario. The range() function starts from zero by default so there are extra lines the solution is to just start from 1:

for i in range(1, n + 1):
| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .