+ 1

[SOLVED] How to print for loop horizontally without repeating the stringD

Hey guys, My codes: print("~Find and Replace~") word = input("Enter a phrase:") find = input("Enter a letter to find:") rep = input("Enter a letter to replace:") a = "" for a in word: a = a.replace(find,rep) print(a,end=" ") I know i should put the end = " " but when i try to add this : print("New phrase:", a, end=" ") it gave me this answer: New phrase: SNew phrase: qNew phrase: mNew phrase: qNew phrase: nNew phrase: tNew phrase: hNew phrase: q How do i print it horizontal without repeating the "new phrase"? Stucked x_X

8th Jun 2018, 5:26 AM
Samantha philip
Samantha philip - avatar
3 Answers
+ 6
What Hatsy said. If you want to start your output with "New phrase: ", put your print function print("New phrase:", end=" ") before you start your for loop.
8th Jun 2018, 5:56 AM
David Ashton
David Ashton - avatar
+ 4
Is there a problem doing: res = "" for a in word: res += a.replace(find,rep) print(res) So that it only prints the processed result once?
8th Jun 2018, 5:44 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Oh it works! Thanks a lot Hatsy and David :D
8th Jun 2018, 8:30 AM
Samantha philip
Samantha philip - avatar