Chris Chris - 2 months ago 12
Python Question

Python recursion function

I am trying to take a number, do floor division on it, until it becomes 0. This must be done using recursion with a base case.
For example:

2 ##(5//2)
1 ##(2//2)
0 ##(1//2)

This is what I have so far:

def Base(number,base):
if result==0:
return False
return Base(result,base)


I think this is what you are looking for

def Base(number,base):

        if number==0:
            return False
            number = number//base
            return Base(number,base)

First of all using result = 1 should be removed as during every recursive call result will be reinitialized to 1 and the following if statement will never work. What you needed to do was to keep on dividing the number recursively till it reaches 0 and print False

I hope it clears your doubt