Answer the question
In order to leave comments, you need to log in
Why is there an extra space at the beginning of a line?
There is the following simple python code:
x = int(input())
b = ""
for i in range(0, x + 1):
b += " " + str(i)
print(b)
Answer the question
In order to leave comments, you need to log in
Obviously there is no need to add a space in the first iteration. Besides, incrementing a string in a loop is bad practice. Yes, and in general it can be done easier:
x = int(input())
print(' '.join(str(i) for i in range(0, x + 1)))
x = int(input())
print(*range(x+1), sep=' ')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question