I have the number A = 1557
How can I find out the amount of this number, if we take each digit separately (1 + 5 + 5 + 7)
Answer 1, Authority 100%
The remainder of the integer division on 10 is the last digit of the number, just in the cycle we fold these numbers by discarding the integer division used by an integer division by 10
def sum_of_digits (num):
Sum = 0.
While Num & GT; 0:
SUM + = NUM% 10
num // = 10
Return Sum.
Print (Sum_of_Digits (1557)) # 18
Answer 2, Authority 100%
in python it is solved so
sum (map (int, str (12345)))