+ 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
3 Réponses
+ 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
+ 1
Try to convert the result into integer:
res = int(count / len(res) )
+ 1
Cyan It's doesn't work.