Question: Please code the following A number, a, is a power of b if it is divisible by b and a/b is a power of b.
Please code the following
A number, a, is a power of b if it is divisible by b and a/b is a power of b. Code a function called is_power that takes parameters a and b and returns True if a is a power of b. Note: you will have to think about the base case.
After writing your is_power function, include the following test cases in your script to exercise the function and print the results: 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))
Don't forget to include descriptive comments in your Python code so I can understand and follow whats going on.
Please use the checklist below to see that you did everything
- Does the submission include theis_divisiblefunction ?
- Does the submission implement anis_powerfunction that takes two arguments?
- Does theis_powerfunction callis_divisible?
- Does theis_powerfunction call itself recursively?
- Does theis_powerfunction include code for the base case of the two arguments being equal?
- Does theis_powerfunction include code for the base case of the second argument being "1"?
- Does the submission include correct output for the five test cases?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
