
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Python week 4 homework assignment's solution
Typology: Exercises
1 / 1
This page cannot be seen from the preview
Don't miss anything!

Sample Answer for Programming Assignment Unit 4 Python Program
def is_divisible(x, y): if x % y == 0: return True else: return False
def is_power(a, b): if a == b: # base case where a/b == 1 return True elif b == 1: # base case where b == 1 but a does not return False else: return is_divisible(a, b) and 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)) Output for Python 3 is_power(10, 2) returns: False is_power(27, 3) returns: True is_power(1, 1) returns: True is_power(10, 1) returns: False is_power(3, 3) returns: True Output for Python 2 ('is_power(10, 2) returns: ', False) ('is_power(27, 3) returns: ', True) ('is_power(1, 1) returns: ', True) ('is_power(10, 1) returns: ', False) ('is_power(3, 3) returns: ', True)