0
Can anyone send me average word length solution in python I have doing in this code all case are done but case1 notdone
word=str(input()) length=len(word) count=0 for lund in word: if(lund==" "): count+=1 count=count+1 print(length//count)
3 Respostas
+ 3
input get you a sentence (list of word separated by spaces).
you need to split() this sentence into a list of words, then you must sum all words length and finally print the average by doing sum_word_length/words_count...
alternativaly, you could get the sum_word_length by counting char ('lund') wich are NOT spaces... or compute it as sentence_length-spaces_count ;)
+ 1
Thanks bro
+ 1
try this
from math import ceil
txt = input().split()
not_char = [".",",","?"]
num_char = 0
for word in txt:
for char in word:
if char in not_char:
continue
num_char += 1
avg = num_char / len(txt)
print (ceil(avg))