subject
Computers and Technology, 21.07.2020 17:01 sw2098

A number, a, is a power of b if it is divisible by b and a/b is a power of b. Write a function called is_power that takes parameters a and b and returns True if a isapowerof b. Note: you will have to think about the base case. Here is a piece of the book:
def is_divisible(x, y):
if x % y == 0:
return True
else: return False
is_divisible(6, 4)
Do Exercise 6.4 from your textbook using recursion and the is_divisible function from Section 6.4. Your program may assume that both arguments to is_power are positive integers. Note that the only positive integer that is a power of "1" is "1" itself.
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))
You should submit a script file and a plain text output file (.txt) that contains the test output. Multiple file uploads are permitted. Don’t forget to include descriptive comments in your Python code. Your submission will be assessed using the following Aspects.
Does the submission include the is_divisible function from Section 6.4 of the textbook?
Does the submission implement an is_power function that takes two arguments?
Does the is_power function call is_divisible? Does the is_power function call itself recursively?
Does the is_power function include code for the base case of the two arguments being equal?
Does the is_power function include code for the base case of the second argument being "1"?
Does the submission include correct output for the five test cases?
I have already done some of the work if you can add the function is_divisible to the programs or change as one of the questions says . thank you!
def is_power(a, b):
if a == b:
return True
if b==1:
return False
elif a%b !=0:
return False
else:
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))

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 01:00
Duplicating objects creates copies that a. move differently than the original object b. erase the original object c. look and act like the original object d. add events to a game
Answers: 1
question
Computers and Technology, 22.06.2019 19:30
The following is an excerpt from a slide presentation. today we will inverse operations solving equations using inverse operations solving inequalities using inverse operations from which part of the presentation does the slide most likely come from? a. introduction b. outline c. body d. conclusion
Answers: 1
question
Computers and Technology, 23.06.2019 19:30
2. fluorine and chlorine molecules are blamed fora trapping the sun's energyob forming acid rainoc producing smogod destroying ozone molecules
Answers: 2
question
Computers and Technology, 24.06.2019 14:00
Text or graphics that print at the bottom of every page are called footings footers headers headings
Answers: 1
You know the right answer?
A number, a, is a power of b if it is divisible by b and a/b is a power of b. Write a function calle...
Questions
Questions on the website: 13722363