Archive for April 17, 2019

Python Project: Sum of power of digits

April 17, 2019 Leave a comment

Python: Sum of power of digits

Problem No.16

In Problem No.16, projectEuler ask to find the Sum of power of digits in the number, for example if we have 2^15 (2 to power of 15) the answer is 23768 then we need to calculate the sum of this number (2+3+7+6+8 ) that’s equal to 26.

The Task: So our task in this project is to find the sum of the digits of (2^1000). To write this as a program and to make it more general we will ask the user to input the number and the power he want, then I start thinking to restrict user from input large numbers that could cause CPU problems, but then i decide to keep it open as is.

The Code:


num=int(input(“Enter a number “))
p=int(input(“Enter a power “))
def sum_of_digits(num,p):


l=[int(i) for i in str(a)]


for x in range (len(l)):


print (“sum =”,t)

Follow me on Twitter..