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

后端 未结 9 1650
甜味超标
甜味超标 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 12:20

    def average():
        value = input("Enter the sentence:")
        sum = 0
        storage = 0
        average = 0
    
        for i in range (len(value)):
            sum = sum + 1
            storage = sum
            average = average+storage
    
        print (f"the average is :{average/len(value)}")
    
        return average/len(value)
    
    average()
    

提交回复
热议问题