Skip to content

Instantly share code, notes, and snippets.

@dnyanesh-github
dnyanesh-github / recursion.py
Created July 31, 2022 12:43 — forked from ayubmetah/recursion.py
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.
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
# Recursive case: keep dividing number by base.
return is_power_of(number/base, base)