110 Answers
New AnswerWrite a program that captures a string that can contain spaces and displays each word in the string, the separator being the space. Example, for the input: "I think so I am" The program displays: word 1: I word 2: think word 3: so word 4: I word 5: am And finally it shows how many words the sentence has. Good luck.
1/14/2018 4:33:04 PM
Med Arezki110 Answers
New Answer@med Nice basic challenge thank you pythonistas take it easy https://code.sololearn.com/cKb3je99nnwL/?ref=app
Python is great at string manipulation d: https://code.sololearn.com/cG4H4S85Gb40/?ref=app I was also able to make it in Ruby :D https://code.sololearn.com/csS7C2E0VP00/#rb And also Java :p https://code.sololearn.com/c9pg0Z7L73wO#java One more in JavaScript :) https://code.sololearn.com/WqLLO1mj7BQP/?ref=app Last one in C# https://code.sololearn.com/cnTfhkEX26Ky/?ref=app
// JS Solution let words = prompt("Enter something", "I think so I am").split(" "); for(var i = 0; i < words.length; i++) { document.write(`word ${i+1}: ${words[i]}<br />`); } document.write("<br />You have entered ", i, " words!");
Slowly I start to think you can do everything in one line in python https://code.sololearn.com/c2EqFC663P7o/#py
My solution: Can handle multiple consecutive spaces. https://code.sololearn.com/WwrZS8v3IKDq/?ref=app
Working now! thanks @Jonathan Pizarra https://code.sololearn.com/WYSEJr7k12KM/?ref=app
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message