Ad
Code
Diff
  • def power(num, p):
        output = num ** p
        return output
    • def power(num, p):
    • assert p >= 0
    • if num == 0 or p == 0:
    • return int(num != 0)
    • if p % 2:
    • return power(num, p - 1) * num
    • return power(num * num, p // 2)
    • output = num ** p
    • return output