Last active
October 20, 2017 14:13
-
-
Save bondnotanymore/9afc91cb1730c9b9f637326fafc69371 to your computer and use it in GitHub Desktop.
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
import sys | |
def if_powerof(n,x): | |
var = n | |
power = 0 | |
if n%x == 0: | |
while var > 1: | |
if var % x == 0: | |
var = var/x | |
power+= 1 | |
else: | |
return "{} is not a power of {}, but just a multiple of 3".format(n, x) | |
#else clause on the while loop; this comes into play when your loop has finished running without any break; | |
else: | |
return "{} is a number, which is {}th power of {}".format(n, power, x) | |
else: | |
return "{} is not even a multiple of {}".format(n, x) | |
print if_powerof(729, 9) | |
print if_powerof(216, 3) | |
print if_powerof(243, 3) | |
print if_powerof(11748, 8) | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment