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:
for i in range(n + 1):
    if n == 0:
    print(" "*(n-i),end="")

I'm getting this output

Height: 4


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):

You must log in to answer this question.

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