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

后端 未结 7 978
小蘑菇
小蘑菇 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:49

    Here's my answer, it's a little bit cleaner:

    def is_power(a, b):
        if a == 1:
            return True
        if a == 0 or b == 0:
            return False
        if a % b == 0 and is_power(a/b, b):
            return True
        else:
            return False
    
    0 讨论(0)
提交回复
热议问题