+ 1

Help, pls. Average in words.

I'm trying to solve the task "Average in words", but all the time i can't pass two last tests and I can't see why. In PyCharm my program works. Here the task: "You are in a college level English class, your professor wants you to write an essay, but you need to find out the average length of all the words you use. It is up to you to figure out how long each word is and to average it out." Here is my decision: https://www.sololearn.com/coach/73?ref=app from math import ceil words = input() letters = 0 words_temp = '' words_lst = [] for i in words: if i.isalpha() or i in '\'`': # for words like "I'm, you're, don't" and etc. if i not in '\'`': words_temp = words_temp + i letters += 1 elif words_temp != '': words_lst.append(words_temp) words_temp = '' print(ceil(letters / len(words_lst)))

22nd Feb 2020, 3:26 PM
Антон Руденков
Антон Руденков - avatar
5 Réponses
+ 3
I tested your code with "hello world". output: 10 average should be 5. each word has a length of 5. two words -> (5 + 5) / 2 = 5
22nd Feb 2020, 4:42 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Thank you :) I thought of everything except that there will be no any punctuation mark at the end of sentence :))
22nd Feb 2020, 4:58 PM
Антон Руденков
Антон Руденков - avatar
+ 1
Антон Руденков Maybe you get more answers if you remove "wtf" ;) You are printing ceil(). This function does not return an integer, right?
22nd Feb 2020, 4:23 PM
Denise Roßberg
Denise Roßberg - avatar
0
Input Format: A string containing multiple words. Output Format: A number representing the average length of each word, rounded up to the nearest whole number. Sample Input: this phrase has multiple words Sample Output: 6
22nd Feb 2020, 4:11 PM
Антон Руденков
Антон Руденков - avatar
0
This function rounds the number to a larger integer and I pass 3 first tests
22nd Feb 2020, 4:29 PM
Антон Руденков
Антон Руденков - avatar