Home python number of numbers in Python

number of numbers in Python

Author

Date

Category

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)))

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions