Solutions and answers to help you learn Python using the Think Python programming textbook
Sunday, March 18, 2012
exercise 6.7 - is_power
"""====================
exercise 6.7
===================="""
def is_power(a,b):
#exception handling
if a == 0 or b == 0:
return False
elif b == 1:
if a == 1:
return True
else:
return False
#normal conditions
if a == 1 or (a/b == 1):
result = True
elif a % b == 0 and a != 0:
result = is_power ( (a/b), b)
else:
result = False
return result
# end is_power
print is_power(64,2)
Labels:
exercise,
thinkpython
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.