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? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 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)

30th Sep 2021, 2:39 PM
Asphalt
Asphalt - avatar
7 Réponses
+ 2
Rajarshi txt = input() words = len(txt.split()) chars = len(txt) - txt.count(' ') print(chars/words)
30th Sep 2021, 3:50 PM
Erlénio.RS
Erlénio.RS - avatar
+ 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 😁
30th Sep 2021, 3:17 PM
Asphalt
Asphalt - avatar
0
Ah yea I was doing c some days ago so that's happened xd. thx for correcting Erlénio.RS
30th Sep 2021, 3:03 PM
Asphalt
Asphalt - avatar
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...
30th Sep 2021, 3:13 PM
Jayakrishna 🇮🇳
0
Rajarshi your code works correctly
30th Sep 2021, 3:23 PM
Erlénio.RS
Erlénio.RS - avatar
0
True 😊though I was wandering if there is any other good method.
30th Sep 2021, 3:24 PM
Asphalt
Asphalt - avatar
30th Sep 2021, 4:05 PM
Asphalt
Asphalt - avatar