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 problem in your code is you forgot to reset the <code>digit_sum</code> when you got an answer.
Put <code>digit_sum = 0</code> before <code>j = list(str(i))</code>. You also start with <code>i = 0</code>. I suggest to start with <code>i = 10</code> since the first 2 digit number is 10.</p>

<p>use this:</p>

<pre><code>[i for i in range(10, 1000000) if i == sum(int(d) ** 5 for d in str(i))]
</code></pre>

<p>equivalent with:</p>

<pre><code>[4150, 4151, 54748, 92727, 93084, 194979]
</code></pre>

<p>using sum:</p>

<pre><code>sum(i for i in range(10, 1000000) if i == sum(int(d) ** 5 for d in str(i)))
</code></pre>

<p>equivalent with:</p>

<pre><code>443839
</code></pre>

python loops sum project digit