Answer to Question #301014 in Python for SosketDon

Question #301014

Do Exercise 6.4 from your textbook using recursion and the is_divisible function from section 6.4.



1
Expert's answer
2022-02-22T06:45:08-0500
def is_divisible(a, b):
    return a % b == 0

def is_power(a, b):
    if a == 1:
        return True
    if b ==  1:
        return False
    if not is_divisible(a, b):
        return False
    return is_power(a/b, b)                        
    
print("is_power(10, 2) returns: ", is_power(10, 2))
print("is_power(27, 3) returns: ", is_power(27, 3))
print("is_power(1, 1) returns: ", is_power(1, 1))
print("is_power(10, 1) returns: ", is_power(10, 1))
print("is_power(3, 3) returns: ", is_power(3, 3))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS