+ 2
[SOLVED] What's the problem with this code?
Coach code link : https://sololearn.com/coach/73/?ref=app My answer : q = input() leni = len(q) inp = q.split(" ") avr = 0 for i in range (leni): avr += len(inp[i]) print(avr/leni)
5 Respuestas
+ 6
Swift
Your code should be like this but remember first you need to remove all special character except space from the string because you need to get average word length
q = input()
inp = q.split(" ")
leni = len(inp)
avr = 0
for i in inp:
avr += len(i)
print(avr/leni)
+ 5
Swift
Try this
import re
import math
q = input()
inp = q.split(" ")
avr = 0
leni = len(inp)
for i in inp:
str = re.sub('[^a-zA-Z0-9\n\.]', '', i)
avr += len(str)
avg = math.ceil(avr / leni)
print(avg)
+ 3
leni = len(inp) because you want the length of the array not the string.
+ 3
If you don't wish to use regex to filter the punctuation, then you might wish to try:
import string
punc = string.punctuation
# which produces
print(punc)
Now you have a filter
Good luck
- 1
jtrh i think you didn't get what the code wants, did you see what the coach code wants?