аватар question@mail.ru · 01.01.1970 03:00

Determination of the number with the largest sum of numbers

Three whole numbers are given. Determine which of them has more the sum of numbers. Calculation of the amount of numbers to organize through the function.

I determine the amount of the number of numbers as follows:

   While  n & gt;  0 :  d = n% 10   n = n //  10    sum += d  

and how to organize through Funkia?

аватар answer@mail.ru · 01.01.1970 03:00
   DeF   sumdigits  ( n ):  Sumd =  0    when  n & gt;  0 :  n, d =  divmod  (n,  10 )  sumd += d  reto  sumditems = [ 123 ,  567 ,  899 ,  999 ] res =  max  (items, key = sumdigits)   print  (res)  #999                                        

Latest

Similar