Python: How can I calculate the average word length in a sentence using the .split command?

后端 未结 9 1647
甜味超标
甜味超标 2021-01-03 11:40

new to python here. I am trying to write a program that calculate the average word length in a sentence and I have to do it using the .split command. btw im using python 3.2

9条回答
  •  礼貌的吻别
    2021-01-03 11:54

    def main():
    
        sentence = input('Enter the sentence:  ')
        SumAccum = 0
        for ch in sentence.split():
            character = len(ch)
            SumAccum = SumAccum + character
    
        average = (SumAccum) / (len(sentence.split()))
        print(average)
    

提交回复
热议问题