+ 1
Someone answer this problem..ill give u a surprise then..
a program that will count the number of words in a sentence by the user.
10 Answers
+ 9
string = "words in a sentence"
print(len(string.split(" ")))
+ 3
If this is a challenge for us, please submit this as an assignment in the Lesson Factory if you haven't yet 😊
https://www.sololearn.com/discuss/1082512/?ref=app
+ 2
Just take the input, count whitespaces, add 1. Assuming correct input, at least.
+ 1
myString=input("Enter a sentence")
myList=myString.split(" ")
wordCount=len(myList)
print(wordCount)
This is basically the same code, but i will break down what's happening..
line 1 ... get user input and store it as a string
line 2 ... split the string into a list. split each word at empty spaces
line 3 ... get the word count by checking the length of the list
line 4 ... Print the word count
+ 1
ty sir..ill try to code this
+ 1
if u r talking about js, then heres the code...
a=prompt("enter a string");
b=a.split(" ").join("");
document.write(b.length);
+ 1
ty for following me sir.. hope you can help me more..im still a beginner..thankyou
0
i really dont have an idea sir..huhu..im so embarass
0
how to do that in particular?
0
what if the user will the one to input the number and get the avg.?