+ 21
[CHALLENGE] Replace Words in a Sentence
The challenge is to take input from the user and replace some specific word with another word as input by the user Input: I like this app.This is fun. Word to be replaced : this To be replaced with : Sololearn Output : I like Sololearn app.Sololearn is fun. Edit: Inbuit functions not allowed! (Like replace( ) ) All languages are welcome. Happy Coding!
25 odpowiedzi
+ 6
JavaScript
https://code.sololearn.com/Wzhp8bRWxcYR
+ 15
Python should be excluded from this competition ;)
print(input().replace(input(),input()))
+ 10
Py~
print(input().replace(x, y))
#where x is word to be replace and y is the new word
+ 10
@infinity
It will work for the word This.. But if you want to make it work for 'this' you can do that too
print(input().lower().replace(input().lower(), input()))
Python still rocks :-}
+ 9
I have edited it!
Enjoy!
+ 8
@dim_knp
replace() function not allowed!!
+ 7
@SQrL Hey! We are not anti-python...!
it is just because its too easy to do it with inbuilt functions...
Wait! Let me edit this question and you can answer in python as well...!
+ 7
JavaScript:
https://code.sololearn.com/Wj63HkU8uTd2/?ref=app
+ 6
You could have tried python as well as I have edited the question
+ 6
@Infinity you want user to input the original text, the word to change and the new word, correct?
And are you expecting a replacement of a single occurrence or every occurrence?
+ 5
This is my try :) using java.
https://code.sololearn.com/cg14ydNO6gDs/?ref=app
+ 5
Here’s my Ruby solution in 8 lines
https://code.sololearn.com/cKHLNox1aX2q/?ref=app
Edit: moving python to a new response
+ 5
@Rohullah Yes off course!
Not only me but everyone is!
But first start the C++ tutorial here and post your doubts...
We all will help you out!
+ 5
good one, i will do
+ 5
@Infinity
Hope this one works for C#. Took me some time to fix all the bugs.
https://code.sololearn.com/cyPKzU5zir1m/#cs
+ 5
My updated Python code
https://code.sololearn.com/cgktTy6BjSCU/?ref=app
+ 4
Just because PY makes it simple it’s time to hate on it?!?
It’s not a ball player on roids; it’s a legitimate language