Sep-27-2020, 12:36 PM
Hello
I am trying to print a print the folliwing
123...n
So, for example, if n = 5, we would print 12345
I played around and Googled, and wrote this
for i in range(1,n):
print (i, end="")
This printed 12, so I changed to:
for i in range(1,n+1):
print (i, end="")
Which seemed to work.
My questions.
1. Why do I need to add n+1 rather than just n
2. In order to get the sequence up to n added, I had to write the end="" bit. I understand in Python 2, this would have been print(i), which makes more sense
Can someone explain how the end="" works?
I am trying to print a print the folliwing
123...n
So, for example, if n = 5, we would print 12345
I played around and Googled, and wrote this
for i in range(1,n):
print (i, end="")
This printed 12, so I changed to:
for i in range(1,n+1):
print (i, end="")
Which seemed to work.
My questions.
1. Why do I need to add n+1 rather than just n
2. In order to get the sequence up to n added, I had to write the end="" bit. I understand in Python 2, this would have been print(i), which makes more sense
Can someone explain how the end="" works?