Answer the question
In order to leave comments, you need to log in
How to find the arithmetic mean of array elements through recursion?
Wrote this, but there must be a more elegant way
test_list = [1, 4, 7]
def func(list1, a=0, b=0):
if list1 == []:
return 0
b += list1[a]
a += 1
if a == len(list1):
return b / a
return func(list1, a, b)
print(func(test_list))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question