Why does my recursive function with if-elif statements return None?

后端 未结 7 1004
小蘑菇
小蘑菇 2020-12-07 03:23

I\'m currently trying to wrap my head around learning Python and I\'ve come to a bit of a stall on recursive functions. In Think Python, one of the exercises is to write a f

7条回答
  •  感动是毒
    2020-12-07 03:42

    you need an additional case, for when both conditionals return false

    def isPower(a,b):
        if a % b != 0:
            return False
        elif isPower((a/b),b):
            return True
        else
            return False
    

提交回复
热议问题