Computers and Technology
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))

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 08:30, ajj3233
On the loan worksheet in cell c9 enter pmt function to calculate the monthly payment for the altamonte springs 2018 facilities loan. ensure that the function returns a positive value and set the reference to cells b5 and b6 as absolute references.
Answers: 2
image
Computers and Technology, 22.06.2019 19:00, SoccerHalo
How is the number 110 written when expanded out to place values in the base 2 (binary) number system? options: 2 x 4 + 3 x 2 + 4 x 1 1 x 2 + 1 x 2 + 0 x 2 1 x 100 + 1 x 10 + 0 x 1 1 x 4 + 1 x 2 + 0 x 1
Answers: 1
image
Computers and Technology, 22.06.2019 19:40, rakanmadi87
Solve the following javafx application: write a javafx application that analyzes a word. the user would type the word in a text field, and the application provides three buttons for the following: - one button, when clicked, displays the length of the word.- another button, when clicked, displays the number of vowels in the word.- another button, when clicked, displays the number of uppercase letters in the word(use the gridpane or hbox and vbox to organize the gui controls).
Answers: 1
image
Computers and Technology, 22.06.2019 23:30, Arealbot
To check spelling errors in a document, the word application uses the to determine appropriate spelling. internet built-in dictionary user-defined words other text in the document
Answers: 1
Do you know the correct 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 in other subjects: