ImLittleNugget
ImLittleNugget ImLittleNugget
  • 01-04-2021
  • Engineering
contestada

i need some help with this


Java programing

i need some help with this Java programing class=

Respuesta :

zayeb27
zayeb27 zayeb27
  • 01-04-2021

def digit_sum(number):

 sumOfDigits = 0

 while number > 0:

     sumOfDigits += number % 10

     number = number // 10

 return sumOfDigits

or you can use,

In [2]: digit_sum(10)

Out[2]: 1

In [3]: digit_sum(434)

Out[3]: 11

or you can use,

digits = "12345678901234567890"

digit_sum = sum(map(int, digits))

print("The equation is: ", '+'.join(digits))

print("The sum is:", digit_sum)

Have a great day <3

Answer Link

Otras preguntas

There are 25 servings in 12.5 once bottle of olive oil. How many oncees are in a serving?
what are the effects of boiling sulfuric acid?
how are airplanes artificially pressurized?
Which Property of Equality should be used first to solve the equation p/7 - 5 = -3 for p Addition Property of Equality Subtraction Property of Equality Multipli
the resultant resistance of two resistance wires in series combination is 108 ohm and in parallel combination is 24 ohm. find the value of individual resistance
Ho does differentiation change an embryo as it develops
what is chemical energy?
what is the farthest distance a human has ever been from earth?
solve for x:    x to the negative 3rd power is equal to 27 over 64
If 5x^2 - 15x = 0 and x ≠ 0, find the value of x. (A) -10 (B) -3 (C) 10 (D) 5 (E) 3