Python Project Euler digit fifth powers
<p><a href="https://projecteuler.net/problem=30" rel="nofollow">Here is the problem</a>:</p>

<blockquote>
  <p>Surprisingly there are only three numbers that can be written as the
  sum of fourth powers of their digits:</p>
  
  <p>1634 = 1^4 + 6^4 + 3^4 + 4^4<br>
     8208 = 8^4 + 2^4 + 0^4 + 8^4<br>
     9474 = 9^4 + 4^4 + 7^4 + 4^4  </p>
  
  <p>As 1 = 1^4 is not a sum it is not included.</p>
  
  <p>The sum of these numbers is 1634 + 8208 + 9474 = 19316.</p>
  
  <p>Find the sum of all the numbers that can be written as the sum of
  fifth powers of their digits.</p>
</blockquote>

<p>And here is my code:</p>

<pre><code>summ = 0
digit_sum = 0
i = 0
while i &lt; 1000000:
    j = list(str(i))
    for x in j:
       digit = int(x) ** 5
       digit_sum += digit
    if digit_sum == i:
       summ += i
       print(i)
    else:
       digit_sum = 0
    i += 1
print(summ)
</code></pre>

<p>Can anyone find out that why I miss a value 4151 which should be one of the correct answer? </p>

<p>The answer to your question is that you don't reset <code>digit_sum</code> every time, only when <code>digit_sum != i</code>.  If you remove the <code>else</code> statement, it should work correctly.</p>

<pre><code>if digit_sum == i:
   summ += i
   print(i)
digit_sum = 0
i += 1
</code></pre>

python loops sum project digit