I am relatively new to python so I apologize for any unconventionality in my code. I have a function which returns some values. I want to repeat this function n times and get the average over the output values for the n iterations (possibly without defining a new function). How can this be done? For example:
def flip_coin(coins):
pr_head = 1
pr_tail = -1
options = (pr_head, pr_tail)
simulation = [[random.choice(options) for x in range(10)] for y in range(coins)]
rep = [i.count(1) for i in simulation]
m = min(rep)
ind_m = rep.index(m)
c_min = simulation[ind_m]
v_min = c_min.count(1) / 10
return v_min
for i in range(n):
flip_coin(coins)
#take average over(v_min)
However I cannot access 'v_min' outside of the function scope and when I iterate the function inside the function (with the exact for loop as above) I get the error:
RecursionError: maximum recursion depth exceeded while calling a Python object.