Q:

Runtime error - where is the mistake in my code

My former problem (which is solved now) was: 
As an input, I have a list of nonnegative whole numbers which are supposed to be the coefficients of a polynomial. But I also want to evaluate the polynomial for a certain number x.
For example:
If we have L=[2,3,1] as an input and x=42 we get 2x^2+3x+1=3655
What I want is for example:
>>>p=polynomial([2,3,1])
>>>p(O)
1 
>>>p(42)
>>>3655

The code is 
def polynomial(coef):
 def poly(x):
    result = 0
    x_n = 1  
    for a in reversed(coef):
        result += a * x_n
        x_n *= x 
    return result
 return poly

What I wanted to do now is to find the inverse , that means the input the is a monotone polynomial and the positive whole number y and I want to find a whole number x such that p(x)=y, and x  should be only in [1,10**10], for example:
>>>p=polynomial([2,3,1])
>>>p(O)
1 
>>>p(42)
>>>3655
>>>invert(3655,p)
42

This is what I have so far, but what I get is a runtime error:
def polynomial(coef):
 def poly(x):
    result = 0
    xn = 1  
    for c in reversed(coef):
        result += c * xn
        xn *= x 
    return result
 return poly

def invert(y,p):

test=10**10

if p(2)>p(1):
    if p(test)>y:
        test=test//2 +(test%2)
        return invert(y,p)
    elif p(test)<y:
        test=test+(test//2)
        return invert(y,p)
    else:
        return test

if p(2)<p(1):
    if p(test)<y:
        test=test//2 +(test%2)
        return invert(y,p)
    elif p(test)>y:
        test=test+(test//2)
        return invert(y,p)
    else:
        return test

The error that occurs is
  ...
  File "poly.py", line 17, in invert
   return invert(y,p)
  File "poly.py", line 14, in invert
  if p(2)>p(1):
   File "poly.py", line 5, in poly
   for c in reversed(coef):
   RuntimeError: maximum recursion depth exceeded while calling a    Python object

What am I doing wrong?

A:

Your invert function recurses forever because you never modify the arguments that you pass to the next call. You do modify test, but that doesn't do you any good, since the inner call will have its own copy of test.
There are a few ways you could fix the issue. You could pass test as an argument to the invert function, with your initial value a default that will be used the first time:
def invert(y, p, test=10**10):
    # ...

    # later, when you recurse:
    test = test // 2      # or whatever
    return invert(y, p, test)    # pass on the modified test value

Another (probably better) approach would be to abandon recursion, and use a loop instead. A while loop seems like it would be appropriate here:
def invert(y, p):
    test = 10**10

    sign = (-1)**(p(2) < p(1))

    while True:
        if p(test) > y:
            test -= sign * (test // 2)
        elif p(test) < y:
            test += sign * (test // 2)
        else:
            return test    # this is the only case that returns

I've left the overall algorithm the same as what your original code does (just streamlined a bit). That algorithm may not be correct if your polynomial isn't strictly increasing or strictly decreasing. You should really compute the derivative of the polynomial at test to determine which direction to adjust in, but I'll leave that to you to figure out.

A:

I wrote the code myself now, limiting everything to the knowledge/skill I only have so far, and it works:
def polynomial(coef):
 def poly(x):
    result = 0
    x_n = 1  
    for a in reversed(coef):
        result += a * x_n
        x_n *= x 
    return result
 return poly

def invert(y,p):

 x=10**10

 while p(x)!=y:
    if p(x)>y:
        w=x
        x=x//2
    elif p(x)<y:
        x=(x+w)//2
    return x

