+ 1

How to answer Sololearn Code Coach challenge?

I just tried the code coach for the first time, and picked up average word length or so def average_length(str): words = str.split(" ") total_lengths, total_words = 0, 0 for word in words: if(word.isalnum()): total_lengths += len(word) total_words += 1 return total_lengths // total_words + (total_lengths % total_words > 0) Yet it says my code produces no output?? What's the format for the challenges?

20th Jul 2021, 6:02 AM
maleeqB
maleeqB - avatar
4 odpowiedzi
+ 3
Hi! When the program needs inputs, you use input(). When the program needs an output, you use print(). If the result is processed inside a function, you have to run the function: def myFunction(arg): …. return res s = input() result = myFunction(s) print(result)
20th Jul 2021, 6:12 AM
Per Bratthammar
Per Bratthammar - avatar
+ 2
ImaleeqB It's not up to Sololearn to call your function, it is up to you to write a code which calls the function. That is how coding works.
20th Jul 2021, 10:16 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Rik Wittkopp It's up to Sololearn to pass me the arg. All things being equal the standard input is a prompt box displayed when i click run. I never knew it would be changed in certain scenario such as this. I think Per Bratthammar 's answer was just on point and the line that's how coding works lol, rather how Sololearn challenge works. write a function that does this and this is a valid question, only if that isn't coding
20th Jul 2021, 12:15 PM
maleeqB
maleeqB - avatar
0
I think sololearn should call my function with the input
20th Jul 2021, 6:12 AM
maleeqB
maleeqB - avatar