I am finding a solution to a problem for which i have figured out the solution in c++ but when i try the same logic in python it gives out RecursionError: maximum recursion depth exceeded in comparison.
x=2
y=500
#Python Implementation
def F(x,y):
    if(x==0):
        return (y+1)%1000
    if(x>0 and y==0):
        return F(x - 1, 1)%1000
    else:
        return F(x - 1, F(x, y - 1))
print(str(F(x,y)))
#C++ Implementation
int f(int x,int y)
{
if(x==0)
    return (y+1)%1000;
if(x>0&&y==0)
    return f(x-1,1)%1000;
else
    return f(x-1,f(x,y-1));
}
int main()
{
 int x,y;
 scanf("%d%d",&x,&y);
 printf ("%03d", f(x,y));
 return 0;
}
Thanks in advance.
 
     
    