Python @ DjangoSpin

PyPro #44 Compute sum of digits of a number

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon
Reading Time: 1 minutes

Sum of digits of a number in Python

Sum of digits of a number in Python

Compute sum of digits of a number: Write a Python Program to calculate the sum of digits of a given number.

Compute sum of digits of a number

number = 432
summation = 0

for digit in str(number):
    summation += int(digit)

print(summation)			# 9

See also:

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon

Leave a Reply