+ 5

# Problem: Average Word Length

Given a sentence as input, calculate and output the average word length of that sentence. To calculate the average word length, you need to divide the sum of all word lengths by the number of words in the sentence. Sample Input: this is some text Sample Output: 3.5 My code that works: sentence = input() words = sentence.split() total = sum(map(len, words))/len(words) print(total)

22nd Feb 2021, 1:38 PM
Max_Mnemo + 23
text = input() length_words = 0 total_words = 0 words = text.split( ) for x in words: length_words += len(x) total_words += 1 average = length_words / total_words print(average)
22nd May 2021, 6:11 PM
HARSHAVARDHAN REDDY + 8
words = input() len_words= len(words) - words.count(" ") tot = len_words / (words.count(" ")+1) print(tot)
28th Aug 2021, 9:30 PM
Hamdambek🖥️🎧 + 3
Here are go. Did this in Python sentence = input("") words = sentence.split() count = 0 sum =0 for x in words: sum += len(x) count += 1 total = sum / count print(total)
21st Apr 2021, 11:33 AM
Joe Hutchens + 3
txt = input("") length = len(txt)-txt.count(" ") splits = txt.split() words = 0 for splits[words] in splits: words += 1 print(length/words)
16th Aug 2021, 3:47 PM
Thamon Muengma
+ 3
New approach without using split and join (). s=str(input()) print((len(s)-s.count(' '))/(s.count(' ')+1))
29th Nov 2021, 3:42 PM
Sonali Kumari + 2
0 text = input() a = text.split() b=len(a) only_alpha = "" for i in text: if i.isalpha(): only_alpha += i print(len(only_alpha)/b) its work try you
22nd Apr 2021, 1:00 PM
Budhabhushan Waghmare + 2
text = input() new_list=text.split() text = text.replace(" ","") print(len(text)/len(new_list))
1st Oct 2021, 8:06 AM
jiaqi chen + 2
new way to do it without using split() good for interview def average(text): space=" " word=[] i=0 new_text=text.replace(" ","") length_of_text=len(new_text) while i < len(text): if text[i] not in space: word_start = i while i<len(text) and text[i] not in space: i +=1 word.append(text[word_start:i]) i +=1 print(length_of_text/len(word)) average(input())
2nd Oct 2021, 6:56 AM
jiaqi chen + 2
text = input() length_words = 0 total_words = 0 words = text.split( ) for x in words: length_words += len(x) total_words += 1 average = length_words / total_words print(average)
4th Jan 2022, 6:22 AM
prateek tiwari + 2
nsenji.inc add a space to 'punc' list. Your 2nd for loop is no need.
11th Apr 2022, 8:51 PM
Jayakrishna 🇮🇳 + 1
Can anyone help me wit it
14th Apr 2021, 12:44 PM
Kaiz arafat + 1
# Super simple!!! text = input() length_words = 0 total_words = 0 words = text.split( ) for x in words: length_words += len(x) total_words += 1 average = length_words / total_words print(average)
3rd Jun 2021, 6:06 PM
LAKSHMI NARAYANAN M + 1
Here is my code solution: text = input() WORDS = text.split(" ") count = 0 for i in text: if not i == " ": count += 1 average = count/len(WORDS ) print (average )
24th Jul 2021, 7:51 PM
Mwaniki Grace Waigumo + 1
text = input() length = len(text) - text.count(' ') count = len(text.split()) print(length/count)
31st Jul 2021, 11:32 AM + 1
Here's a new approach and keeping it a 2 line code text = input().split() print(len("".join(text)) / len(text))
12th Sep 2021, 12:41 AM
TrebleClef20 + 1
text = input() result = len(text.replace(' ', '')) / len(text.split()) print (result)
23rd Oct 2021, 7:08 PM
Morteza Abdollahi + 1
check this out here: text = input() text_list=list(text.split()) text_length=len(text_list) letter=list(text) letter_length=len(letter) -(text_length-1) average=letter_length/text_length print(average)
7th Dec 2021, 3:50 AM + 1
text = input() a = text.split() d = 0 for i in a: c = i.split() e = len(i) d += e print(d/len(a))
3rd Jan 2022, 4:08 PM 