Letter frequency | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Letter frequency

Why my solution of "Average Word Length" task is wrong? text = input() new_text = text.split() number_of_signs = len(new_text) total = int((len(text)/len(new_text))) answer = print(total)

29th May 2021, 3:56 PM
Dariusz Jenek
Dariusz Jenek - avatar
6 Answers
+ 1
the most obvious way to do the second point is using a for loop over the list... and inside it add each items (words) length to number_of_signs...
30th May 2021, 3:41 PM
visph
visph - avatar
0
because you're not doing it the right way... you must add each words length in the 'new_text' list, and use that sum (wich doesn't count spaces of 'text' string) instead of len(text) ;)
29th May 2021, 4:00 PM
visph
visph - avatar
0
Provide tag with programming type
29th May 2021, 4:19 PM
‎ ຸ
0
I do really not know how to do it. Could You give me some tips, please? Thank You very much ina advance!
30th May 2021, 10:39 AM
Dariusz Jenek
Dariusz Jenek - avatar
0
you should: 1) initialize the number_of_signs (letters) variable to zero 2) iterate the 'new_text' list and add each items (words) length to the number_of_signs variable 3) then you can compute the average by dividing the number_of_signs by the number of words (len(new_text))
30th May 2021, 10:50 AM
visph
visph - avatar
0
How can I do the second point?
30th May 2021, 2:02 PM
Dariusz Jenek
Dariusz Jenek - avatar