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

A submarine was situated 450 feet below sea level. If it descends 300 feet, what is its new position?
What is the expanded form of 249,104,330
Identify as expression or equation 9=2x-4
tomas grandfather is 100 years old.tomas grandfather is 10 times as old as tomas .how los is tomas?
how to put risk and wages in a sentence
Which words in the sentence make up the adverb phrase? Which word does it modify? During the winter, he plays tennis indoors. A. during the winter; modifies pla
how do you write 701,245 in two other forms?
Which answer best summarizes the main benefit of slavery to the colonies? Slavery helped secure settlements in the New World against invading forces. Buying sla
What ideas did the Romans borrow from the Greeks
What issue were the Virginia and New Jersey Plans attempting to resolve?