 help please | Sololearn: Learn to code for FREE!

-1

Im doing python's data structures and im in the 2nd project wich i have to calculate the average word length. And i need to divide the sum of all word lengths by the number of words in the sentence. example taked it by the project: 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 and my code takes the spaces as a character and i dont know how to not do it,i used strip() but it didnt work and im gonna try a different way: texto = input() lista=texto.split() resultado=texto/len(lista) print(resultado)

0

resultado should hold sum of length of each word divided by number of words (mean of word length): len(lista) give you the number of words, but texto is the input text... you should iterate lista and add each word length, then divide the result by len(lista) resultado = 0 for word in lista: resultado += len(word) resultado /= len(lista)

0

Thank you very much for your help ill try the code

0

Thank you very much visph for yout help

-1

a="hey world hello" b=a.split() print(sum(list(len(i) for i in b))/len(b)) Or a="hey world hello" b=a.split() add=0 for i in b: add+=len(i) print(add/len(b))