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

Multiply these fractions (Lowest Terms) a) 2 x 3/4 b) 3 x 3/5 c) 4 x 1/3 d) 6 x 2/5 e) 1/2 x 1/4 f) 4/5 x 2/3 g) 5/6 x 3/4 h ) 1/10 x 2/3 i) 2 1/5 x 1/
How many flags are in this wolld ;)
David helped his father stock the pond with baby catfish and blue gill. They put in a total of 75 fish. If the number of blue gill was doubled and the number of
If the length of each side of a square prism is ten feet. Find the total surface area of this object
What were the reasons for the failure of the League Nations?
All of the following are types of lyric poetry except; A. tankas. B. ballads. C. sonnets. D. madrigals.
the length L of a spring is given by L=(3/4)F + 5 where F is applied force. What force F will produce a length of 8?
What is the solution: (9x+2)(4x^2+35x-9)=0
A particle travels in a circle of radius 82 cm and with a centripetal acceleration of 4.7 m/s2. How long does the particle take to complete one revolution?
Perimeter of a square with an area of 81cm2