-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
M_average-word-length.py
39 lines (25 loc) · 1014 Bytes
/
M_average-word-length.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
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
"""
import string
def roundup(x: float):
if int(str(x).split(".")[1]) == 0:
return int(x)
else:
return int(x) + 1
text = input()
newtext = text.translate(str.maketrans('', '', string.punctuation))
words = newtext.split()
averagelen = sum(map(len, words))/len(words)
print(roundup(averagelen))