I am struggling with the All Your Base (https://exercism.org/tracks/python/exercises/all-your-base) exercise. So far I have managed to convert the given digits into a base-10 number, but am unsure of how to convert this into the desired base. My code is below:
def rebase(input_base, digits, output_base):
if input_base < 2:
raise ValueError("input base must be >= 2")
if output_base < 2:
raise ValueError("output base must be >= 2")
if not all(0 <= d < input_base for d in digits):
raise ValueError("all digits must satisfy 0 <= d < input base")
valueOfDigits = 0
for d in digits:
valueOfDigits += d * input_base ** (len(digits) - d)