Click here to Skip to main content
15,889,034 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I just tried to make the print on the same line using the 'end=' argument but it is causing problem with the print statement very next to it.

I want the print to be on the new line but not happening.
please tell me how to fix it.

Thanks

What I have tried:

word = input("Please enter: ")
sum = 0
for i in word:
    print(i, end='')
    sum += 1

print(word)
print(sum)
Posted
Updated 29-Apr-21 1:52am

1 solution

Try
Python
word = input("Please enter: ")
sum = 0
for i in word:
    print(i, end='')
    sum += 1
print()
print(word)
print(sum)
 
Share this answer
 
Comments
Francis Sadiq 29-Apr-21 8:09am    
Thank you very much my dear. Can you explain why it was happening?
CPallini 29-Apr-21 8:39am    
Because
print(i, end='')
(correctly) prints just the character, without a newline.
At the end of the string, however, you do need a newline.

By the way, you're welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900