In Python, write function mssl() (minimum sum sublist) that takes as input a list of integers. It then computes and returns the sum of the maximum sum sublist of the input list. The maximum sum sublist is a sublist (slice) of the input list whose sum of entries is largest. The empty sublist is defined to have sum 0. For example, the maximum sum sublist of the list [4, -2, -8, 5, -2, 7, 7, 2, -6, 5 ] is [5, -2, 7, 7, 2] and the sum of its entries is 19.

>>> 1 = [4, -2, -8, 5, -2, 7, 7, 2, -6, 5]

>>> mssl(1)

19

>>> mssl([3,4,5])

12

>>> mssl([-2,-3,-5])

0

In the last example, the maximum sum sublist is the empty sublist because all list items are

negative.

Respuesta :

Limosa

Answer:

Following are the program in Python Programming Language.

#define function

def mssl(l):

 maxlen = x = 0

 #initialize two variable  

 for i in l:

 #set for loop  

   x = max(x + i, 0)

 #check the max value of sum

   maxlen = max(maxlen, x)

 

 return maxlen   #return the result

list01=[]

 #list type variable

while True:

  #set while loop

 x=int(input("Enter the value or 0 to  stop: "))

 #get input from the user

 if(x==0):

  #set if statement

   break

 #break the loop

 else:

 

   list01.append(x)

#append the value of x in listo1

print(mssl(list01)) #call the function

Output:

Enter the value or 0 to  stop: -2

Enter the value or 0 to  stop: -3

Enter the value or 0 to  stop: -5

Enter the value or 0 to  stop: 0

0

Explanation:

Here, we define the function "mssl()" and pass an argument to its parameter are the variable "l".

Then, inside the function, we initialize two integer type variable "maxlen" or "x" to 0.

Then, set the for loop and then return the value of the variable "maxlen".

Then, we initialize an empty list data type variable in which we pass the values.

Then, we set the while loop inside it we get the input the user in the variable "x" and then we set the if-else statement.

Finally, we call the function "mssl()" and pass the variable "list01" as an argument.