Guest User

Untitled

a guest
Dec 16th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. while n>0:
  2. d=n%10
  3. n=n//10
  4. sum+=d
  5.  
  6. def sumdigits(n):
  7. sumd = 0
  8. while n > 0:
  9. n,d = divmod(n, 10)
  10. sumd += d
  11. return sumd
  12.  
  13. items = [123, 567, 899, 999]
  14.  
  15. res = max(items, key=sumdigits)
  16.  
  17. print(res)
  18. #999
  19.  
  20. def sumdigits(n):
  21. return sum([ int(i) for i in str(n) ])
  22.  
  23. items = [123, 567, 899, 999]
  24. res = max(items, key=sumdigits)
  25. print(res)
  26. 999
Add Comment
Please, Sign In to add comment