+ 22
[ASSIGNMENT] 🚩🚩 Add ! And ?? In Spaces
Write a program to accept user's input with spaces. If there is a single space in that input, add ! sign . If there are 2 spaces, add ?? sign. Example: Input:abc de feg Output: abc!de??feg Input: I love Sololearn Output: I!love?? Sololearn You can use any languages Note: I also submitted this challenge to Lesson Factory😉
14 Answers
+ 14
For some reason, this occasionally says compilation error on Code Playground.
https://code.sololearn.com/cF3s29Qem3Jg/?ref=app
+ 23
https://code.sololearn.com/cJ2ixOBJNuKa/?ref=app
+ 19
For some reason, this occasionally says compilation error in Code Playground.
https://code.sololearn.com/cLX0xixfJ7tY/?ref=app
+ 16
https://code.sololearn.com/cCSDzrX2QOw6/?ref=app
+ 14
alert(prompt().replace(' ', '??').replace(' ', '!'))
+ 8
Python:
print(input().replace(“ “, “??”).replace(“ “, “!”))
+ 8
+ 7
https://code.sololearn.com/cKnxQGmvySWg/?ref=app
+ 5
Saludos desde Argentina!
https://code.sololearn.com/c69WiPWv20ex/?ref=app
+ 5
[edit: this is fixed] [meta, temporary] I've ID'd the thing giving the Compilation Error and reported with feedback. if you get the error and your code usually runs, just run again.
+ 4
https://code.sololearn.com/c6l4ciKr4ePe/#py
using regular expression functions #python
+ 3
function format(input){
var output = input.replace(/\s{2}/g, "??").replace(/\s{1}/g, "!");
return output;
}
console.log(format("I love Sololearn.")); // logs "I??love!Sololearn."
console.log(format("abc de feg")); // logs "abc!de??feg"
or short
console.log("I love Sololearn.".replace(/\s{2}/g, "??").replace(/\s{1}/g, "!")); // logs "I??love!Sololearn."