CBSE Class 12 Computer Science
Question 77 of 105
Python Revision Tour II — Question 4
Back to all questionsword_list = eval(input("Enter a list of words: "))
total_length = 0
for word in word_list:
total_length += len(word)
average_length = total_length / len(word_list)
print("Average length of words:", average_length)Enter a list of words: ["apple", "banana", "orange", "kiwi"]
Average length of words: 5.25
- The code prompts the user to enter a list of words and assigns it to the variable
word_list. - We iterate over
word_listusingforloop. Inside the loop, length of each word gets added tototal_lengthvariable. - Average length is calculated by dividing
total_lengthby the number of words inword_list.