The function below takes one parameter: a list of strings (string_list). Complete the function to compute the total combined length of all of the strings in the list The recommended approach for this: (1) create a variable to hold the current sum and initialize it to zero, (2) use a for loop to process each element of the list, adding its length to your current sum, (3) return the sum at the end.

Respuesta :

Answer:

def total_lengths(string_list):

   total = 0

   for s in string_list:

       l = len(s)

       total = total + l

   return total

a_list = ["black", "blue", "white"]

print(total_lengths(a_list))

Explanation:

Inside the function:

- Initialize total to zero to hold the sum

- In the for loop, assign the length of the each string to the l and add these values to the total

Then

- Create a list to check the function

- Call the function, pass the list as a parameter and print the result

fichoh

The required code written in python 3 which returns the total sum of the strings in a list goes thus :

def sum_strings(string_list):

#initialize a function named average_string which takes in a list of string as parameter

total_length = 0

#initialize total length of string to 0

for word in string_list :

#iterate through each string on the list

total_length += len(word)

#adds the length of each string to the total length of the string.

return total_length

#return the total value of the string length

A sample run of the function is given here and the output attached.

string_list = ['dog', 'cat', 'mouse']

print(sum_strings(string_list))

Learn more :https://brainly.com/question/15352352

Ver imagen fichoh