- 1

Why does that the test case 1 is failing???

import math n = input().split(" ") a = 0 for i in n: if i not in "@#&+()/?": for x in i: b = len(x) a = a+b x = len(n) print(math.ceil(a/x)) 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

4th Jul 2021, 2:29 PM
Shahir
Shahir - avatar
4 odpowiedzi
+ 2
import math n = input().split(" ") a = 0 c = "" for i in n: for j in i: if j not in "@#&+()/?": c+=j #b = len(x) a +=1 x = len(n) print(math.ceil(a/x))
4th Jul 2021, 3:17 PM
Simba
Simba - avatar
0
In the given code only few punctuation mentioned i.e. --> "@#&+()/?" But there are many more like ---> ~" ' - _ ] [ { .....etc. TIP : rather the excluding the counting of punctuation count the alphabet :)
4th Jul 2021, 3:17 PM
Jitendra
Jitendra - avatar
0
import math import re w = re.sub(r"\W", " ", input()).split() a = sum(map(len, w))/len(w) print(math.ceil(a)) # split default separator is space # regex \W match not word chars (ascii alphanumerics + underline) # re.sub replace pattern with substitute string in input string # sum return sum of iterable # map return iterable mapped with function
4th Jul 2021, 5:08 PM
visph
visph - avatar