Python,C,C++ and JAVA programs for CBSE, ISC, B.Tech and I.T Computer Science and MCA students

The Programming Project: Power digit sum : Problem 16 Python Code

Saturday, August 30, 2014

Power digit sum : Problem 16 Python Code

Power digit sum : Problem 16 Euler Project

215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 21000?

Python Code

def powerDigitSum():
    l = 2**1000
    strNumb = str(l)
    sumFact = 0
    for i in range(len(strNumb)):
        sumFact = sumFact + int(strNumb[i])
    print "sum of the digits in the number! is",sumFact
powerDigitSum()

No comments:

Post a Comment