+ 1
Why This Code Isn't Working True?
This code is giving close result but not true. Cold you help me? Ex. my output 4.8 but must be 5. Here code: https://www.sololearn.com/coach/73?ref=app The purpose of the code is calculate mean of words in sentence.
12 Antworten
+ 1
Can you post your syntax? Not the question. You ac insert it by pressing the + with a circle around it.
Like this
https://code.sololearn.com/c5Td5Lrco5s3/?ref=app
+ 1
import math
string =input()
st1= ""
cnt=0
punct='''! ()-[]{};:'"\,<>./?@#$%^&*_~'''
for x in string.lower():
if(x==" "):
cnt+=1
if x in punct:
string = string.replace(x,"")
print(math.ceil(len(string)/(cnt+1)))
0
Post code
0
Here it is:
https://code.sololearn.com/cXS37ZNowAlB/?ref=app
Sorry i am new at Sololearn and its my first question 😕
0
Nadirhan Şahin what's the input where you got 4.8?
0
Odyel i doesnt matter always inputs are wrong
0
Nasif Rahman Of course, youre right. I forgot punctuation. How can i fix it?
Thanks for the 2nd info 👍 But, Can't mean be float?
0
Nasif Rahman i tried to do what you said. But new error occured 😥
https://www.sololearn.com/discuss/2514730/?ref=app if you want to help
0
Nasif Rahman Thanks. its working 👍
0
Mahesh Kantariya What a shorty code? Importance of libraries. Thanks for the answer.
0
import math
sent=input().replace("?","")
sent= sent.replace("!","")
sent= sent.replace(":","")
sent= sent.replace("-","")
sent=sent.replace("_","")
words= sent.split()
avg= sum(len(word) for word in words) / len(words)
print (math.ceil(avg))
Try this one
ceil() will apply smallest integer function on the result.
This function will give smallest integer larger than the argument(a float)
0
Hetharth Sachdeva Can you increase the variety of punctuation?