+ 2

Is there a better way of doing this without using ceil?

Average Word Length 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. Task: Takes in a string, figure out the average length of all the words and return a number representing the average length. Remove all punctuation. Round up to the nearest whole number. 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 https://code.sololearn.com/cNX81Mmdm16k/?ref=app

3rd May 2020, 2:54 AM
Fanatic
Fanatic - avatar
3 ответов
+ 2
Using math.ceil is perfectly fine. After all, that's what the task required.
3rd May 2020, 5:14 AM
Tibor Santa
Tibor Santa - avatar
+ 1
You should try this one .. import math sentence=input() if sentence .count("?")>0: length=len(sentence)-1 else: length=len(sentence ) space=sentence.count(" ") words=space+1 letters=length-space average=letters/words round=math.ceil(average) print(round)
19th Sep 2021, 12:10 AM
DivyanshuYash
DivyanshuYash - avatar
0
import math b = input().split() sum=0 for x in b: c=len(x) if x.count("?")>0: c-= x.count("?") sum+=c print(math.ceil(sum/len(b)))
4th May 2022, 8:10 PM
Mohamed Wagdy
Mohamed Wagdy - avatar