How to find the number of words in an input? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to find the number of words in an input?

27th Apr 2020, 2:07 PM
Aman Muhammed
Aman Muhammed - avatar
15 Answers
+ 2
In Python3. Like Abhay wrote. example = input("") splited = example.split(" ") lenofexample = len(splited)
27th Apr 2020, 8:00 PM
Sven_m
Sven_m - avatar
+ 2
Yup but in python also it's the same ,using split method and then applying len function,😁
27th Apr 2020, 2:19 PM
Abhay
Abhay - avatar
+ 1
yochanan sheinberger he didn't mentioned the language tho method is same I guess ,split it and take the length!
27th Apr 2020, 2:14 PM
Abhay
Abhay - avatar
+ 1
If you mean Javascript then... use this:- <input type="text" id="myText"> <button id="myBtn">Submit text<button> <script> //hope this helps buddy! var content = document.getElementById("myText").value; document.getElementById("myBtn").onClick = function() { alert(content.length); } </script>
27th Apr 2020, 2:21 PM
KASH
KASH - avatar
+ 1
a="hello world".split() print(len(a))
27th Apr 2020, 2:24 PM
Abhay
Abhay - avatar
0
var input = document.getElementById("myInput").value; var inputArray = Input.split(); consol.log(inputArray.length + 1);
27th Apr 2020, 2:13 PM
yochanan sheinberger
yochanan sheinberger - avatar
0
Mention the language in tags where you written input
27th Apr 2020, 2:13 PM
Abhay
Abhay - avatar
0
In which language?
27th Apr 2020, 2:14 PM
KASH
KASH - avatar
0
Abhay I assumed he meant java script. I was definitely wrong... ):
27th Apr 2020, 2:17 PM
yochanan sheinberger
yochanan sheinberger - avatar
0
Its easy to find the number words (split method).. Find the number of letters (dont take it seriously... .take it as a funny project and do this ) . Note : this is for Aman sir .....
27th Apr 2020, 5:04 PM
Md. Mursalatul Islam Pallob
Md. Mursalatul Islam Pallob - avatar
0
A=input() A.split() len(A.split())
28th Apr 2020, 9:08 PM
Oyedeeoke
Oyedeeoke - avatar
0
oke oyediran 2 ppl already answered ,I dunno why ppl keep posting same thing when it has been answered or did you added some extra info in your comment that I am missing ? If it is so sorry!!
28th Apr 2020, 9:25 PM
Abhay
Abhay - avatar
0
Count for the number of blank space
29th Apr 2020, 9:48 AM
Harshvardhan Rathore