Question: Need help to create this function = calculateTotalWords(paragraphs). I
ID: 3664984 • Letter: Q
Question
Question: Need help to create this function = calculateTotalWords(paragraphs). I have completed the first function on paragraphs and now stuck on finding the the total words which I have on the last line, any help to understanding this one, thanks.
book = [['ï', 'the', 'project', 'gutenberg', 'ebook', 'of', 'the', 'declaration', 'of', 'independence']]
def calculateTotalParagraphs(paragraphs):
 Â
return len(paragraphs)
calculateTotalWords(paragraphs) = the function. Returns the total number of words given a book in the form of a list of lists of strings using parameter paragraphs.
Explanation / Answer
def calculateTotalParagraphs(paragraphs):
return len(paragraphs)
def calculateTotalWords(paragraphs):
words = 0
for para in paragraphs:
for word in para:
words = words + len(word)
return words
book = [['ï', 'the', 'project', 'gutenberg', 'ebook', 'of', 'the', 'declaration', 'of', 'independence']]
print(calculateTotalWords(book))
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.