Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5
Amruta Dhokchaule Split string to get number of words and count character of string without special characters. Then divide number of characters with number of words to get average.
7th Sep 2021, 1:25 PM
A͢J
A͢J - avatar
+ 2
Runtime Terror[ Busy ] Maybe according to you my solution is wrong but according to the practice it is right solution and I did the same.
7th Sep 2021, 1:44 PM
A͢J
A͢J - avatar
+ 2
Runtime Terror[ Busy ] According to your explanation and my solution both will give same result. Let's see your example: hello hire I said number_of_character_without_special_character/ number_of_words So according to your example: number_of_character_without_special_character = 5 + 4 = 9 number_of_words = 2 It means (5 + 4) / 2 = 4... Now you see what is the difference between your solution and my solution? Amruta Dhokchaule there should be "average word length" instead of "average length" in your question.
7th Sep 2021, 1:59 PM
A͢J
A͢J - avatar
+ 2
Hi Amruta! I assume that you're trying to complete the first module project of the python for data structures. Here, you don't have to think about special characters or statistics things. Only you have to consider about whitespace between each words. For that, you can use split() function to get all words. So, its length gives you the number of words in given input while its length-1 gives you the number of whitespaces.
7th Sep 2021, 4:21 PM
Python Learner
Python Learner - avatar
+ 1
# Amruta Dhokchaule # You can edit the code as per your need s="i am python lover" chars=len(s)-s.count(" ") suum=sum(range(chars)) print(f"Average is : {suum//chars}")
8th Sep 2021, 1:54 PM
Ratnapal Shende
Ratnapal Shende - avatar