Average Words Length Python
For Average Words Length challenge in Python the function split() always returns a class ‘str’ to me rather than a class ‘list’. Anyone has seen same behavior? Thanks https://code.sololearn.com/ciImr1czh929/?ref=app
Can you Pls post the code to understand it..?
Sergiu Panaite You are using strip() function ,not split() function. strip() returns a string with removing leading and trailing spaces. split() returns a list with splitting into words..
can’t belive I was that blind, I always had impression I was writing split but was actually using strip. I feel embarassed ☹️. Thanks guys
Sergiu Panaite not to worry.. 👍👍
Thanks [user id=202974]Sonic[/user] , your code returns a list indeed, mine still returns a string. I’ve added the code in my original description.
a = input() x=(len(a)-a.count(" ")-a.count(".")-a.count(",")-a.count("?"))/(a.count(" ")+1) print(int(x)+(x>x//1)) #Hope this code is working fine; did it in a hurry, might have bugs.
Here is the code text = input() spl = text.split() print(spl) no_char = len(text) no_elment=len(spl) print (no_char) print (no_elment) print (20/3) #print ("%.2f" % (no_char/no_elment) print("%.2f" % round((no_char/no_elment), 2)) but the output is coming as 6.666666666666667 instead of 6.0
i use text = input() word = text.split() only_alpha = text.replace(" ", "") print(len(only_alpha) / len(word))
Unable to overload +
I have tried every way I could find but still I can't display my local images ..what am I doing wrong?
Pls rectify the errors.
Python list half printed
Find the error please.