This is my solution for 4 / 15


def digit_sum(n):
total_sum = 0
total_string = []
m = str(n)
for x in m:
for x in total_string:
total_sum += int(x)
return total_sum

print digit_sum(1738)



Go to the python interpreture and do this

import this

It will print out some stuff, check it out.

Now as to why I asked you to do that, your code has a ton of extra stuff that is purely not needed.

def digit_sum(data):
    This function converts the data into a string, then iterates over it adding it to
    a list. It then converts it back into an int when it adds it to the list. After that 
    it uses the built-in function sum() to add the list together.
    return sum([int(digit) for digit in str(data)])

While you are still new to Python I would get into the habit of programming in the most pythonic way that you are capable of. Also as a note codeacademy's courses are not pythonic is the slightest. Go above and beyond and you will appreciate python more that way.


What do you mean by pythonic? I'm assuming it alludes to using built-in functions and importing functions others have made instead of creating your own from scratch?

Would you recommend for beginners to familiarise themselves with certain modules and their functions?


from the Python Wikipedia entry:

A common neologism in the Python community is pythonic, which can have a wide range of meanings related to program style. To say that code is pythonic is to say that it uses Python idioms well, that it is natural or shows fluency in the language, that it conforms with Python's minimalist philosophy and emphasis on readability.

Another thing to consider is one Python engineer’s words:

To describe something as clever is not considered a compliment in the Python culture.

You’ll learn modules and functions naturally as you practice more and more, but reading documentation never hurt anyone B)