+ 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.

24th Sep 2020, 1:51 PM
Nadirhan ƞahin
Nadirhan ƞahin - avatar
12 Respostas
+ 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
24th Sep 2020, 1:58 PM
Odyel
Odyel - avatar
+ 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)))
26th Sep 2020, 12:29 PM
Mahesh Kantariya
0
Post code
24th Sep 2020, 1:52 PM
Odyel
Odyel - avatar
0
Here it is: https://code.sololearn.com/cXS37ZNowAlB/?ref=app Sorry i am new at Sololearn and its my first question 😕
24th Sep 2020, 2:01 PM
Nadirhan ƞahin
Nadirhan ƞahin - avatar
0
Nadirhan ƞahin what's the input where you got 4.8?
24th Sep 2020, 2:20 PM
Odyel
Odyel - avatar
0
Odyel i doesnt matter always inputs are wrong
24th Sep 2020, 2:27 PM
Nadirhan ƞahin
Nadirhan ƞahin - avatar
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?
24th Sep 2020, 2:29 PM
Nadirhan ƞahin
Nadirhan ƞahin - avatar
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
24th Sep 2020, 4:16 PM
Nadirhan ƞahin
Nadirhan ƞahin - avatar
0
Nasif Rahman Thanks. its working 👍
24th Sep 2020, 4:31 PM
Nadirhan ƞahin
Nadirhan ƞahin - avatar
0
Mahesh Kantariya What a shorty code? Importance of libraries. Thanks for the answer.
26th Sep 2020, 12:33 PM
Nadirhan ƞahin
Nadirhan ƞahin - avatar
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)
26th Sep 2020, 1:15 PM
Hetharth Sachdeva
Hetharth Sachdeva - avatar
0
Hetharth Sachdeva Can you increase the variety of punctuation?
26th Sep 2020, 1:24 PM
Nadirhan ƞahin
Nadirhan ƞahin - avatar