I have a question about printing on the same line using a for loop in Python 3. I was looking for an answer, but I could not find any relevant one.
So, I have something like this:
def function(variable): some code here return result item = input('Enter a sentence: ') while item != '': split = item.split() for word in split: new_item = function(word) print(new_item) item = input('Enter a sentence: ')
When the user enters a "short sentence" into the sentence, the function must do something with it and it should be printed on the same line. Say the function adds 't' to the end of each word, so the output should be
In shortt sentencet
However, at the moment, the output is:
IN
Shortt
sentencet
How can I print the result on the same line? Or should I create a new line so that
new_string = '' new_string = new_string + new_item
and it repeats, and in the end do I type new_string?
Someone
source share