So I have been solving this problem on HackerRank and got stuck thinking about how to print the output of the problem on the same line. After that, I gave up and looked up the answer on the internet. Even though it worked all confused about how and why.
https://www.hackerrank.com/challenges/python-print/problem?isFullScreen=true
here is the Link of the Problem
I did reach this point and got stuck:
n = int(input())
for i in range(1, n+1):
print(i)
The output should be 123...n.
My Output was 1 2 3 . . . n(every number on a new line)
The output should be in the same line. So here is the required soln to the problem
n = int(input())
for i in range(1, n+1):
print(i, end="")
Can Anyone explain how it works? How did this , end=""
changed the whole solution