Created
October 15, 2021 23:16
-
-
Save msyvr/9fbb25c031cac5e4754c05158343cfcc to your computer and use it in GitHub Desktop.
Given a base, is a number a power of that base?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ispowerof(n, base): | |
''' | |
if n is a power of b, return True, else return False | |
''' | |
test = False | |
if n % base == 0: | |
k = int(n / base) | |
for i in range(k+1): | |
print(i) | |
print(base**i) | |
if base**i == n: | |
print(f'Exponent = {i}') | |
test = True | |
break | |
return test | |
if __name__ == "__main__": | |
b = int(input("what positive integer base do you want to check for?:\n")) | |
n = int(input('Let\'s check if a number is a power of that base.\nWhat number?: ')) | |
print(ispowerof(n, b)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment