I have a problem: i need to find an average of the list using this scheme:
First of all, we find an average of two elements, three elements..... len(list) elements and form a new list using averages. The use .pop() and find all averages again. Function should stop when len(list) == 2. Recursion should be used.
Example:
list: [-1, 4, 8, 1]
1 step:
- find an average of
[-1, 4], [-1, 4, 8], [-1, 4, 8, 1] - Then we form a new list:
[1.5, 3.66..., 3](averages) - Then find averages of new list:
[1.5, 3.66...], [1.5, 3.66..., 3] - Then we form a new list:
[2.5833.., 7.222...](averages) - When
len(list) == 2, find an average of this two elements.
Answer is 2.652777.
What should i write:
jada = []
while True:
print 'Lst elements:'
a = input()
if (a == ''):
break
jada.append(a)
print 'Lst is:' + str(Jada)
def keskmine(Jada):
for i in range(len(Jada) - 1):
...
jada.pop()
return keskmine(Jada)
Actually, this is a part of a homework, but i don't know how to solve it.