Christy Tay Christy Tay - 22 days ago 8
Python Question

How to strip white spaces in Python without using a string method?

I am fairly new to programming and have been learning some of the material through HackerRank. However, there is this one objective or challenge that I am currently stuck on. I've tried several things but still cannot figure out what exactly I am doing wrong.

Objective: Read N and output the numbers between 0 and N without any white spaces or using a string method.

N = int(input())
listofnum = []

for i in range(1, N +1):
listofnum.append(i)
print (*(listofnum))


Output :

1 2 3

Answer

You can print numbers inside the loop. Just use end keyword in print:

print(i, end="")
Comments