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