Question
# Step 1 will be to start off with the is_divisible and print the output def is_divisible(x, y): if x % y == 0: return
# Step 1 will be to start off with the is_divisible and print the output
def is_divisible(x, y):
if x % y == 0:
return True
else:
return False
#is_divisible code runs successfully well without any code or syntax errror and this supports the direction specified in the text book,
# As you write larger functions, you might find yourself spending more time debugging.
# To deal with increasingly complex programs, you might want to try a process called incremental development.
# The goal of incremental development is to avoid long debugging sessions by adding and testing only a small amount of code at a time.
# The next phase is to add to try using recursion
OUTPUT:
"C:\Users\Young Joseph\AppData\Local\Programs\Python\Python37-32\python.exe" "C:/Users/Young Joseph/PycharmProjects/interpreneurapp/tryme4.py"
Process finished with exit code 0
# Step 2 will be to add the recursion to is_divisible and print the output
def is_divisible(x, y):
if x % y == 0:
return True
else:
return False
def recurse(x, y):
if x % y == 0:
return True
else:
return False
# after adding recursion, the code prints successfully
OUTPUT
"C:\Users\Young Joseph\AppData\Local\Programs\Python\Python37-32\python.exe" "C:/Users/Young Joseph/PycharmProjects/interpreneurapp/App.py"
Process finished with exit code 0
# Step 3 will be to add is_power to both is_divisible and recurse then print the output
def is_divisible(x, y):
if x % y == 0:
return True
else:
return False
def recurse(x, y):
if x % y == 0:
return True
else:
return False
def is_power(x, y):
if x % y == 0:
return True
else:
return False
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))
# after adding is_power, the code prints successfully giving outputs of True
OUTPUT:
"C:\Users\Young Joseph\AppData\Local\Programs\Python\Python37-32\python.exe" "C:/Users/Young Joseph/PycharmProjects/interpreneurapp/App.py"
is_power(10, 2) returns: True
is_power(27, 3) returns: True
is_power(1, 1) returns: True
is_power(10, 1) returns: True
is_power(3, 3) returns: True
Process finished with exit code 0
Question
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?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started