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

How did the Declaration of Independence change the nature of the American Revolution?
How do you work out the problem 84 divided by4
What is a group of organisms that look alike and can reproduce among their selfs ?
Simplify (7-5i)(-3+9i)-(5+6i)^2
What is a group of organisms that look alike and can reproduce among their selfs ?
Graph the line using intercepts: 4x-3y=12
when we look at a leaf, we see the colors of light that are reflected off its surface. how does the relatively low flow of oxygen in green light?
A number cube is rolled 24 times and lands on 2 four times and on 6 three time. Find the experimental probability of not landing on a 6
Newtons third law of motion is also known as the law of ?
what is the simplest square root of 1345? no decimals please