Average word length problem. | SoloLearn: Learn to code for FREE!


Average word length problem.

Hi, myself varun (clearly written on id but i like an intro). So, i am stuck in the average word length code coach, for 2 days. I tried every relevant way of trying but didnt Succeeded. (I am using ruby) The only problem is every time I round the numbers to floor() they last 4 cases are wrong and when i use ceil() the 1st case is wrong. So my code is below :- strings = gets.chomp.to_s letter = strings.split("") letter.delete(" ") word = strings.split(" ") letters = letter.size().to_f words = word.size().to_f average = (letters / words) num1 = average.round(1) num2 = average.to_i log = num1 - num2 x = 0.5 if log <= 0.5 print average.ceil() else print average.floor() end I used round also but wasnt helpful. Please give me some ideas as answers as i am stuck and please try providing answers in Ruby. For further Inquiries you can DM me i would like to have a solution. ☺ Thanks in advance.

9/4/2020 5:05:06 AM

Varun Sharma

7 Answers

New Answer


Evan Flair , word.delete "?" does only delete "?". Right? The task description from this code coach mentions, that all punctuation has to be removed, which means some more special characters.


Evan Flair Thank you, Thank you and Thank you very much. But i have some queries. 😅 Can you provide the logical flow please. As some of the statements are kind of different to me. And yeah a more particular question is this, that you removed "? ", how do you know that whether it would be in the string input or not?. well, when I removed "? " my test cases where also correct BUT i thought that i dont know what they would answer so i let it be the old answer. (which caused all this chaos) Thanks again cause it helped .☺


Lothar Yeah, you are right. 🤔


So, in the second test case there were 3 dots "... ", should they also needed to be removed. 🤔?