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, 21.06.2019 14:10
In a flashdisk wich icon can you use to open files in computer
Answers: 1
question
Computers and Technology, 21.06.2019 22:00
Which is produced by the endocrine system to control how cells and organs function
Answers: 2
question
Computers and Technology, 24.06.2019 20:30
How is energy expended in active transport
Answers: 1
question
Computers and Technology, 25.06.2019 08:10
What is the requirement for self-contained recovery devices
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
question
Mathematics, 08.03.2021 15:40
question
Mathematics, 08.03.2021 15:40
question
Physics, 08.03.2021 15:40
Questions on the website: 13722362