How does one add the digits of a large number?

前端 未结 3 1779
你的背包
你的背包 2021-01-27 18:12

I have been trying to add the individual digits of a larger number for a while now, and I\'m having some trouble. I was wondering if anyone could help me.

For example, s

3条回答
  •  醉话见心
    2021-01-27 19:05

    one more alternative is to use build in list([iterable]) function

    bigNumber = '23455869654325768906857463553522367235'
    print sum(int(x) for x in list(bigNumber))
    print sum(int(x) for x in list(bigNumber)[5:11])
    

提交回复
热议问题