I want to write a function that gets base and some numbers that are in base n as its input and returns sum of the args in base n. I thought I first get the first digit of the numbers and calculate the sum and then the other digit and so on... but the thing is I can't get the second digit and my code just adds the first digit: (n between 2 and 10)
def sum_base(base, *args):
tot = 0
s = ""
for num in args:
rem = num % base
tot += rem
if tot >= base:
tot = tot % base
carry = tot // base
s += str(tot)
num = num // 10
return s
print(sum_base(2, 1111,1111,11111,10111))
could anyone help me modify the code? Thanks