0

Av word length

text =input() count =text.split() count = 0 sum = 0 for x in text: sum += len(x) count += 1 Av = int(sum)/count print(Av)

30th May 2021, 7:31 AM
Harsh Jain
Harsh Jain - avatar
9 Respostas
+ 2
count = text.split() should be: text = text.split()
30th May 2021, 7:39 AM
visph
visph - avatar
+ 1
Done it's running TQ
30th May 2021, 7:40 AM
Harsh Jain
Harsh Jain - avatar
0
what is your question/problem? I guess that your code doesn't work, because you are assigning the word list to 'count' variable instead of 'text' ;P
30th May 2021, 7:33 AM
visph
visph - avatar
0
I din understand I am still in python data structure
30th May 2021, 7:34 AM
Harsh Jain
Harsh Jain - avatar
0
The output is always 1
30th May 2021, 7:34 AM
Harsh Jain
Harsh Jain - avatar
0
Given a sentence as input, calculate and output the average word length of that sentence. To calculate the average word length, you need to divide the sum of all word lengths by the number of words in the sentence. Sample Input: this is some text Sample Output: 3.5 Explanation: There are 4 words in the given input, with a total of 14 letters, so the average length will be: 14/4 = 3.5
30th May 2021, 7:35 AM
Harsh Jain
Harsh Jain - avatar
0
read again my post: I explained why ^^
30th May 2021, 7:35 AM
visph
visph - avatar
0
So what shld I replace the word count
30th May 2021, 7:37 AM
Harsh Jain
Harsh Jain - avatar
0
Ohk
30th May 2021, 7:39 AM
Harsh Jain
Harsh Jain - avatar