Q. Write a short Python code segment that adds up the lengths of all the words in a list and then prints the average (mean) length.

Answer :-

count= 0
lst = eval(input("Enter a list :-"))

for i in lst:
    count += len(i)
    
print("Mean:" ,count/len(lst))

Output :-

Enter a list :-[ "Path", 'Walla', "Python" ]
Mean: 5.0

>>>

Enter a list :- [ "HTML", "CSS", "C++", "C#", "JAVA"]
Mean: 3.2

>>>


6 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. output of this program??

    ReplyDelete
  2. This program is showing error in my pc 😥😭😭😭

    ReplyDelete
  3. what if the list is nested?

    ReplyDelete
  4. can we use statistics module?

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post