Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 楼层划分的递归函数_Python_Algorithm_Recursion_Division_Floor - Fatal编程技术网

Python 楼层划分的递归函数

Python 楼层划分的递归函数,python,algorithm,recursion,division,floor,Python,Algorithm,Recursion,Division,Floor,我正在创建一个递归函数,它基本上不使用“/”操作符就可以操作楼层分割。我已经算出了函数,但只有当输入n为正时,我才努力算出当n

我正在创建一个递归函数,它基本上不使用“/”操作符就可以操作楼层分割。我已经算出了函数,但只有当输入n为正时,我才努力算出当n 我当前的代码:

def quotient( n , d ):

    if (n >= d):
        return quotient(n - d, d) + 1

    else: 
        return n

你可以这样做:

def quotient( n , d ):

    if (0<=n<d):
        return 0
    if (n >= d):
        return quotient(n - d, d) + 1
    if n<0:
        return quotient(n + d, d) - 1
def商(n,d):

如果(0)非常感谢你!