I want to write a Python script that will read a test from the console and output the average number of characters per word,but i have some problem with punctuation and newline characters . there is my code.
def main():
allwords = []
while True:
words = input()
if words == "Amen.":
break
allwords.extend(words.split())
txt = " ".join( allwords)
n_pismen = len([c for c in txt if c.isalpha()])
n_slov = len([i for i in range(len(txt) - 1) if txt[i].isalpha() and not txt[i + 1].isalpha()])
for char in (',', '.', ';'):
txt = txt.replace(char, '')
txt.replace('\n', ' ')
words = txt.split()
print(sum(len(word) for word in words) / len(words))
if words:
average = sum(len(words) for words in allwords) / len( allwords)
if __name__ == '__main__':
main()
Our Father, which art in heaven,
hallowed be thy name;
thy kingdom come;
thy will be done,
in earth as it is in heaven.
Give us this day our daily bread.
And forgive us our trespasses,
as we forgive them that trespass against us.
And lead us not into temptation,
but deliver us from evil.
For thine is the kingdom,
the power, and the glory,
For ever and ever.
Amen.
normal will be output 4.00,but i just get 1.00