Why This Code Isn't Working True? | SoloLearn: Learn to code for FREE!

+2

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

9/24/2020 1:51:41 PM

Impervious

+6

Nadirhan Şahin try this👇 alpha = "abcdefghijklmnopqrstuvwxyz" bet = input() num = 0 space = 1 for i in range(0, len(bet)): for j in range(0, len(alpha)): if bet[i] == alpha[j]: num += 1 break if bet[i] == ' ': space += 1 if num % space == 0: print (num // space) else: print (num // space + 1)

+6

Nadirhan Şahin codes written in a code coach can't be seen by others directly. So you have to copy-paste it in the Code Playground and share the link of that code here.😇

+4

Nadirhan Şahin here are two things that you need to remember that, 1. There can punctuation marks i the input, but you have to count the whole length without punctuation. 2. Use // instead of / to get an integer value after the division.

+4

Nadirhan Şahin you can use a list, where all the alphabets will be stored as elements. You need to iterate through the list by using a for loop and range() function and check, if the letter is in the input or not. And use a counter variable to count the total number of letters in the input.😇

+1

Post code

+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

Here it is: https://code.sololearn.com/cXS37ZNowAlB/?ref=app Sorry i am new at Sololearn and its my first question 😕

+1

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?

+1

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

+1

Nasif Rahman Thanks. its working 👍

+1

import math string =input() st1= "" cnt=0 punct='''! ()-[]{};:'"\,<>./[email protected]#\$%^&*_~''' for x in string.lower(): if(x==" "): cnt+=1 if x in punct: string = string.replace(x,"") print(math.ceil(len(string)/(cnt+1)))

+1

Mahesh Kantariya What a shorty code? Importance of libraries. Thanks for the answer.

+1

Hetharth Sachdeva Can you increase the variety of punctuation?

0

Nadirhan Şahin what's the input where you got 4.8?

0

Odyel i doesnt matter always inputs are wrong

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)