Project Euler problem 30

Below is the solution to problem 30 from Project Euler. It’s written in Python, a programming language I’m trying to learn.

#!/usr/bin/env python 
# Project Euler problem 30

narc_sum = 0
for number in range(100, 200000):
        # Transform the number into a string
        string = str(number)
        # Transform the string into a list
        lst = list(string)
        sum = 0 
        for i in range(len(lst)):
                # Add the members of the list to the fifth power
                sum = sum + (int(lst[i])**5)
        if (number == sum):
                # Add all numbers and store in narc_sum value
                narc_sum = narc_sum + number
                print "Sum is ",narc_sum

Leave a Reply