+ 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()
2 Antworten
+ 2
You'll also need to remove all punctuation and round up your resulting average.
+ 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(" ")