小编CIP*_*HER的帖子

如何计算一个数字是否是另一个数字的幂?

如何让is_power_of函数返回数字是否是给定基数的幂?假设基数为正数。

def is_power_of(number, base):
  # Base case: when number is smaller than base.
  if number < base:
    # If number is equal to 1, it's a power (base**0).
    return __

  # Recursive case: keep dividing number by base.
  return is_power_of(__, ___)

print(is_power_of(8,2)) # Should be True
print(is_power_of(64,4)) # Should be True
print(is_power_of(70,10)) # Should be False
Run Code Online (Sandbox Code Playgroud)

python python-3.x

-2
推荐指数
1
解决办法
1万
查看次数

标签 统计

python ×1

python-3.x ×1