import math
def sumOfDigit(num):
sum_of_digits = 0
while num > 9:
sum_of_digits += num % 10
num = int(num/10)
sum_of_digits += num
return sum_of_digits
print sumOfDigit(math.pow(2,1000))
This is what I thought of for Project Euler #16, and it works fine for smaller numbers. But when I tried 21000, the code gave me 1289.0 instead of the answer 1366 (Found this on the internet). I think the problem might have to do with the size of the number, but I'm not sure. Any points in the right direction will be appreciated. Thanks in advance!
Edit: Here is the question https://projecteuler.net/problem=16