Why this code doesn't solve the average word length problem's last test case | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Why this code doesn't solve the average word length problem's last test case

def string_average_length(): string = input("") string_words = len(string.split()) string_spaces = len(" ") string_length = len(string) string_only_words = string_length-string_spaces string_average_length = string_only_words/string_words print(int(string_average_length)) string_average_length()

24th Jul 2020, 9:09 AM
Arrahman Abtahi
2 Answers
+ 2
You'll also need to remove all punctuation and round up your resulting average.
24th Jul 2020, 9:19 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
string_spaces = len(" ") 🔼 this will always be 1, it gives you the length of " " space character (which is always 1), try using: string_spaces = string.count(" ")
24th Jul 2020, 9:14 AM
Bagon
Bagon - avatar