+ 12
[SOLVED] Python Text analyzer course exercise.
I'm currently stucked at Text analyzer exercise in Sololearn python course. Here's the question Given text as input, output the number of words it contains. Sample Input hello world Sample Output 2 ___________________________________ Below is my code but the code analyzer keeps saying my approach and code is wrong. Anyone who has passed this level should help here. I just want to forcefully get this before progressing further with the course. https://code.sololearn.com/c10T0Ic9tD7c/?ref=app
19 Answers
+ 15
Stonny a code respectively your solution is tested automatically with a few inputs. So the solution‘s code should look like as follows:
txt = input()
#your code goes here
print(len(txt.split()))
+ 7
string = str(input())
result = len(string.split())
print (str(result))
+ 5
This will help you:
https://code.sololearn.com/cskwrdXNy0lL/?ref=app
+ 3
Stonny , first the text should be read as input. The other thing is that you don't need to print additional text, only the number of the words.
+ 3
Martin Taylor
I thought the code analyzer should be able to dictate a successful program without having me do exactly or write down the exact input it wants.
I'm totally confused and pissed with that code analyzer. 😶
+ 3
very sample
print(len(input().split(' ')))
+ 3
Stefan
thanks for the code. it helps 🎅😊
+ 3
Pretty cool code!
+ 3
it simply provides inputs and compares the outputs against an expected value in the exmple the outputs is = 2
+ 2
JaScript
thank you so much for the help. 😊🎅
+ 2
Martin Taylor
I appreciate your effort and the time you took to explain this.
Thank you so much.
I now understand how the sololearn "text harness" works.
🎅🎅🙂🙂
+ 2
txt = input()
#your code goes here
word_list = txt.split()
number_of_words = len(word_list)
print(number_of_words)
+ 1
Hips
thank you so much for simplifying the code.🙂🎅🎅
+ 1
txt = input()
number=0
for i in txt:
if i ==" ":
number +=1
print(number+1)
###################
new_list=txt.split()
print(len(new_list))
both works
+ 1
string = str(input())
result = len(string.split())
print (str(result))
+ 1
txt = input()
#your code goes here
words=txt.split(" ")
numberOfWords=len(words)
print(numberOfWords)