+ 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

20th Dec 2020, 11:38 AM
Stonny
Stonny - avatar
19 odpowiedzi
+ 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()))
20th Dec 2020, 2:31 PM
JaScript
JaScript - avatar
+ 7
string = str(input()) result = len(string.split()) print (str(result))
20th Dec 2020, 2:14 PM
Stefan
Stefan - avatar
20th Dec 2020, 12:20 PM
JaScript
JaScript - avatar
+ 4
JaScript thanks for the code but It's not actually what I was looking for... I want to know why sololearn python code analyzer rejects my programs while it sure does what it supposed.
20th Dec 2020, 2:01 PM
Stonny
Stonny - avatar
+ 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.
20th Dec 2020, 12:16 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 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. 😶
20th Dec 2020, 2:10 PM
Stonny
Stonny - avatar
+ 3
very sample print(len(input().split(' ')))
21st Dec 2020, 10:56 AM
Hips
Hips - avatar
+ 3
Stefan thanks for the code. it helps 🎅😊
21st Dec 2020, 12:07 PM
Stonny
Stonny - avatar
+ 3
Pretty cool code!
31st Dec 2020, 7:12 AM
Abdulhakim Sani
Abdulhakim Sani - avatar
+ 3
it simply provides inputs and compares the outputs against an expected value in the exmple the outputs is = 2
4th Jan 2021, 7:17 AM
Abdulhakim Sani
Abdulhakim Sani - avatar
+ 2
JaScript thank you so much for the help. 😊🎅
21st Dec 2020, 12:08 PM
Stonny
Stonny - avatar
+ 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. 🎅🎅🙂🙂
21st Dec 2020, 12:11 PM
Stonny
Stonny - avatar
+ 2
txt = input() #your code goes here word_list = txt.split() number_of_words = len(word_list) print(number_of_words)
15th Dec 2021, 4:07 PM
Matt Webb
+ 1
Hips thank you so much for simplifying the code.🙂🎅🎅
21st Dec 2020, 12:08 PM
Stonny
Stonny - avatar
+ 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
29th Sep 2021, 7:05 AM
jiaqi chen
jiaqi chen - avatar
+ 1
string = str(input()) result = len(string.split()) print (str(result))
1st May 2022, 6:31 AM
Vraj Soni
Vraj Soni - avatar
+ 1
txt = input() #your code goes here words=txt.split(" ") numberOfWords=len(words) print(numberOfWords)
11th Nov 2022, 12:51 AM
Benjamin Fadina
Benjamin Fadina - avatar