How can I solve "Average word Lenght" in Python Data Structure project. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I solve "Average word Lenght" in Python Data Structure project.

Hi, I had the problem while solving "Average Word Lenght" in Python Data Structure project. When the code runs, It's print very long float value. How can I fix this? My Code: https://code.sololearn.com/c0JBT1R111s0/?ref=app

1st Feb 2021, 11:54 PM
Satakun Utama
Satakun Utama - avatar
3 Answers
+ 2
Yes, thanks for the update. The problem here is in the for loop, instead of counting the character each word (res), the for loop is counting all characters including whitespaces (text). Possible Solution: 1. Instead of iterating "text", iterate the "res" list instead to iterate each word. 2. Increment the length of that word to "count" 3. Remove the subtraction or incremention of count and len(res). If you have more questions, please feel free to ask. Thanks. https://code.sololearn.com/ccC4IspC4msO/?ref=app
2nd Feb 2021, 1:02 AM
noteve
noteve - avatar
+ 1
Try to convert the result into integer: res = int(count / len(res) )
2nd Feb 2021, 12:53 AM
noteve
noteve - avatar
+ 1
Cyan It's doesn't work.
2nd Feb 2021, 12:57 AM
Satakun Utama
Satakun Utama - avatar