I tried to solve the following problem. However, it is returning invalid syntax in line 5. Also I could not solve it. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

I tried to solve the following problem. However, it is returning invalid syntax in line 5. Also I could not solve it.

Your friend sent you a message, however his keyboard is broken and types a # instead of a space. Replace all of the # characters with spaces and output the result. txt = input() #your code goes here for i in txt: if (txt[i]==#): txt=txt.replace(txt[i], " " ) print(txt)

24th Dec 2020, 2:29 AM
Rajat Banerjee
Rajat Banerjee - avatar
14 Answers
+ 5
correct code txt = input() b = txt.replace('#',' ') print(b)
25th Jul 2021, 10:20 PM
Hugues Rodrigue Tha Andela
Hugues Rodrigue Tha Andela - avatar
+ 4
txt = input() #your code goes here print (txt .replace("#", " "))
15th Dec 2021, 3:42 PM
Matt Webb
+ 4
I solved this with the following: msg = input() print (msg.replace("#", " ")) This way the print function is integrated with the replace so no need for a separate line to print.
8th Feb 2022, 6:44 PM
Peter S
+ 3
txt = txt.replace("#", " ") - - - - - - - - - - - - - You dont actually need to iterate all the elements cause the iteration is already happening behind or in the background when you use "replace" This read as: replace "#" with " "
24th Dec 2020, 2:37 AM
noteve
noteve - avatar
+ 1
Here is how I solved it: text = input() print(text.lower())
11th Jan 2022, 1:52 PM
Quality Crew
Quality Crew - avatar
0
Thank you so much. It was much easier than I thought for 2 hours.
24th Dec 2020, 12:23 PM
Rajat Banerjee
Rajat Banerjee - avatar
0
I solved it this way: x = msg.replace("#", " ") print(x)
17th Sep 2021, 1:23 AM
Geo
0
x = input() txt = x.lower() print(txt)
1st Dec 2021, 4:34 PM
Juned Miah
0
txt = input() print(txt.replace("#", " "))
28th Feb 2022, 4:57 AM
Jake Ambrose
Jake Ambrose - avatar
0
txt = input() txt = txt.replace('#',' ') print(txt) done..!
5th Mar 2022, 4:16 PM
Nikhila
0
txt = input() txt = txt.replace('#',' ') print(txt)
16th Mar 2022, 1:59 PM
rasfa
0
msg = input() msg = msg.replace('#', ' ') print(msg)
30th May 2022, 3:34 PM
Evgen Shamanayev
Evgen Shamanayev - avatar
0
txt = input() #your code goes here txt= (txt.replace("#"," ")) print(txt)
7th Jul 2022, 3:26 PM
Zocimo Orozco Valencia
- 1
txt = input() #your code goes here print(txt.replace("#"," "))
28th Jun 2021, 11:16 AM
Eduards