Fill in the blanks to make the is_power_of function return whether the number is a power of the given base. Note: base is assumed to be a positive number. Tip: for functions that return a boolean value, you can return the result of a comparison.
Answers
Answered by
3
Answer:
3 to the power 4
Answered by
26
Answer:
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 number == 1
result = number//base
# Recursive case: keep dividing number by base.
return is_power_of(result, base)
Explanation:
Similar questions