Question: How is work the function ? Please explain step by step . Why is the output 20 ?Thanks in advance . def mystery(lst): total =

How is work the function ? Please explain step by step . Why is the output 20 ?Thanks in advance .

def mystery(lst):

total = 0

n = len(lst)

for i in range(n):

for j in range( i+1,n):

total += sum (lst[i:j])

return total

lst=[1,2,3,4]

print(mystery(lst))

output is 20

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!