Hello.
With this function
I think i got it
With this function
def digit_sum(number): value = str(number) digits = [int(x) for x in value] return sum(digits)You can get the sum of one splited item given from the user. How can i make it so it does the same fuction but instead it will be given a list and lastly how can i replace the results that this function gave me with the number that it initially got in order to make the calculation? For example if it got the list
list=[1,25,5,30]and it made the calculations,so we have as a unofficial result 7,3.My goal is to get the summed numbers which in case are 7 and 3 and add them to the list that the fuction got my numbers from. So we must have
list=[1,7,5,3]Thank you
I think i got it
lista=[1,96,3] lista_sum=[] def digit_sum(LIST): for i in range(len(LIST)): value = str(LIST[i]) digits = [int(x) for x in value] lista_sum.append(sum(digits)) print (sum(digits)) digit_sum(lista) print (lista_sum)If you can suggest something please feel free to!