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 11:10
Look at the far left lane in the picture. explain what the red car is doing and what it needs to do to travel safely.
Answers: 2
question
Computers and Technology, 22.06.2019 22:20
Avariable of the data type arrays is storing 10 quantities. what is true about these quantities? a. the quantities all have different characteristics. b. the quantities all have the same characteristics. c. five quantities have the same and five have different characteristics. d. it is necessary for all quantities to be integers. e. it is necessary for all quantities to be characters.
Answers: 2
question
Computers and Technology, 23.06.2019 14:30
The option enables you to modify a slide element in most presentation applications.
Answers: 2
question
Computers and Technology, 24.06.2019 17:30
What is the next step if your volume does not work on computer
Answers: 2
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: 13722362