Why are you iterating over f ? Use recursion as such: 

```
   function = f[0];
    if function == 'x':
        return x
    if function == 'y':
        return y
    if function == 'prod':
        #pprint.pprint(f[1])
        #pprint.pprint(f[2])
        return evaluate_random_function(f[1], x, y) * evaluate_random_function(f[2], x, y)        
    if function == 'cos_pi':
        return math.cos(math.pi*evaluate_random_function(f[1], x, y))
    if function == 'sin_pi':
        return math.sin(math.pi*evaluate_random_function(f[1], x, y))
```