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

What is 1/4 - [-3/8] =
Kevin gave ben $4.90 in dimes and quarters.if 10 coins were quarters how many coins were dimes which equation models this problem
NEED NOW! Find the vertex of the graphed function. f(x) = |x − 4| + 3
An ATP molecule is made up of which of the following? Select one: a. Carboxylic group, ribose sugar, adenine base b. Phosphate groups, deoxyribose sugar, thymin
Which of the following statements is not true about a vocational or technical education program?
what is the greatest common facter of 4 and 8
1052×291 i need answer asap
the following sentence uses which principal part of the verb? we only swim when the water is warm
What it’s one example of telling detail from “witness to the tragedy”
Matthew earned 325$ giving haircuts. He charged 25$ for each haircut how many haircuts did he give