Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote