Question: PYTHON: Write a recursive function base that has two parameters, n, a base 10 positive integer, and b, an integer between 2 and 9. The
PYTHON:
Write a recursive function base that has two parameters, n, a base 10 positive integer, and b, an integer between 2 and 9. The function returns the base b representation of the number n. The base b representation of a number uses the digits 0,..,b-1 and the place of the digits indicate powers of the base. For example: 887 (base 10) = 2*7**3 + 4*7**2 + 0*7**1 + 5*7**0 = 2405 (base 7)
Fortunately, this expansion means that is easy to compute using the % and // operators with respect to the base. For example, suppose that we want the base 7 representation of 887. Then, the last digit is 5 because 887%7=5. And the preceding digits are 240 because 887//7 = 126, and the base 7 representation of 126 is 240. You may need to conduct additional research on base b representations. Sample runs:
>>> base(0,3) # write 0 in base 3
'0'
>>> base(5,3) # write 5 in base 3
'12'
>>> base(887,7) # write 887 in base 7
'2405'
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
