+ 1
Any other good ways to do it ?So at first I was doing it without .islpha and it was giving me wrong values so any other method?
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 Explanation: There are 4 words in the given input, with a total of 14 letters, so the average length will be: 14/4 = 3.5 My try(it's correct btw ): text = input() words = len(text.split()) char = 0 for i in text: if i.isalpha(): char = char + 1 print(char/words)
7 ответов
+ 2
Rajarshi
txt = input()
words = len(txt.split())
chars = len(txt) - txt.count(' ')
print(chars/words)
+ 1
I did some edit in code though it small thing but yea Jayakrishna🇮🇳 . Erlénio.RS pointed it out first and yea dint know why he deleted his comment maybe cuz I corrected it 😁
0
Ah yea I was doing c some days ago so that's happened xd. thx for correcting Erlénio.RS
0
Code working correctly but may you not using commenting ?
What is code there and what is text for comments there? Pls clarify..
Sharing code link by saving will be better...
0
Rajarshi your code works correctly
0
True 😊though I was wandering if there is any other good method.
0
Ty Erlénio.RS