John has recently started learning algorithms in Python, then he tried to create his first one that counts the average word length in a sentence. Unfortunately, he made an error. Try to find the line(s) with this error and correct it.
Algorithms in Python
There is an error in the code
Report a typo
Sample Input 1:
I want to go home.Sample Output 1:
2.6Write a program in Python 3
sentence = input()
def aver(sent):
for sym in [',', '!', '?', ';', '.', '"', "'"]:
sent = sent.replace(sym, '')
words = sent.split()
total = 0
for word in words:
total = total + len(word)
if len(word) != 0:
result = total / len(word)
else:
result = 0
return result
print(aver(sentence))
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.