Write a recursive python function int_log_base(base, number) that does the follo
ID: 3763709 • Letter: W
Question
Write a recursive python function int_log_base(base, number) that does the following:
The integer log base x of y is the number of times you must divide y by x to get a number between 1 (inclusive) and x (exclusive).For example, int_log_base(3, 1112) is 6 because 1112 / 3 / 3 / 3 / 3 / 3 / 3 (which has 6 divisions in it) is 1.525... which is between 1 and 3. You may assume the base and number will both be strictly greater than 1. Do not use the ** operator or any math library functions in your solution; do it recursively instead.
Can't use a loop
Explanation / Answer
#! /usr/bin/Python
def int_log_base(base, number):
quotient = number/base;
if (quotient >= 1 and quotient < base):
return 1;
return 1+int_log_base(base, quotient)
print int_log_base(3,1112);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.