title: Python - Project Euler #80, understanding the error
body: <p>Project Euler problem #80 seems straightforward:</p>
  
  <p><a href="https://projecteuler.net/problem=80" rel="nofollow">https://projecteuler.net/problem=80</a></p>
  
  <p>Using the decimal module to calculate the square root to a given precision:</p>
  
  <pre><code>from decimal import Decimal, localcontext
  
  def prob80():
      total = 0
      for x in range(1,100):
          with localcontext() as ctx:
              ctx.prec = 100
              total+=sum([int(i) for i in str(Decimal(x).sqrt())[2:]])
      return total
  print prob80()
  </code></pre>
  
  <p>I return 40308 which I understand is someway off the correct answer. For the digital sums of the square root of the first ten natural numbers I return:</p>
  
  <p>0
  475
  441
  0
  472
  470
  397
  463
  0
  456</p>
  
  <p>Where's the error here? I think it's down to some sort of rounding error but I can't seem to work it out.</p>