title: Project Euler #16 on Python
body: <pre><code>import math
  
  def sumOfDigit(num):
      sum_of_digits = 0
      while num &gt; 9:
          sum_of_digits += num % 10
          num = int(num/10)
      sum_of_digits += num
      return sum_of_digits
  
  print sumOfDigit(math.pow(2,1000))
  </code></pre>
  
  <p>This is what I thought of for <code>Project Euler #16</code>, and it works fine for smaller numbers. But when I tried 2<sup>1000</sup>, the code gave me <code>1289.0</code> instead of the answer <code>1366</code> (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!</p>
  
  <p>Edit: Here is the question <a href="https://projecteuler.net/problem=16" rel="nofollow noreferrer">https://projecteuler.net/problem=16</a></p>