Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

  1. Does the submission include theis_divisiblefunction ?
  2. Does the submission implement anis_powerfunction that takes two arguments?
  3. Does theis_powerfunction callis_divisible?
  4. Does theis_powerfunction call itself recursively?
  5. Does theis_powerfunction include code for the base case of the two arguments being equal?
  6. Does theis_powerfunction include code for the base case of the second argument being "1"?
  7. Does the submission include correct output for the five test cases?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions