Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while n>0:
- d=n%10
- n=n//10
- sum+=d
- def sumdigits(n):
- sumd = 0
- while n > 0:
- n,d = divmod(n, 10)
- sumd += d
- return sumd
- items = [123, 567, 899, 999]
- res = max(items, key=sumdigits)
- print(res)
- #999
- def sumdigits(n):
- return sum([ int(i) for i in str(n) ])
- items = [123, 567, 899, 999]
- res = max(items, key=sumdigits)
- print(res)
- 999
Add Comment
Please, Sign In to add comment