0
I need help
I don't know why this code didn't work I have error in test case4 s=input() a=s.lower() b=a.split() lst=[] a1=ord('a') alfa=[chr(i)for i in range(a1,a1+26)] for letter in a: if letter in alfa: lst.append(letter) avrg=len(lst)/len(b) if avrg==int(avrg): avrg=int(round(avrg)) print(avrg) else : avrg=int(round(avrg)+1) print(avrg)
9 Antworten
+ 2
Btw you can check if its an alphabetical letter with isalpha()
You dont need the alfa list
+ 1
What is the purpose of your code and what are test cases?
+ 1
What is the input? Is it a list of words or a sentence?
Or just tell me the name of the challenge than i can see the task by myself
+ 1
import math
s = input().split()
count=0
for word in s:
count += len(''.join(i for i in word if i.isalpha()))
print(math.ceil(count/len(s)))
+ 1
I would have done it this way for example
+ 1
1. You dont need to make it to lower case and then check for the ord number cause yoi can just use isalpha() as i said before
2.you can also just count the letters and not append it to a list and after that use the length
3.you dont need to care about it the value is already a whole number and not a floating number if you use math.ceil cause this method always rounds up
+ 1
It work thank you jnn
0
This is a challenge I want to get the average length of the words
0
Challenge name is average length of words and the input is sentence