I wanted to post this in python faq, but when I tried searching for it under the topics when creating this post it didn’t come up, and when I went to the python faq forum I couldn’t click on the topic button (it was greyed out). When I tried to reply to an already made post it had been locked my a moderator, so am having to create a new post in order to ask my question.
Anyway the question I have is related to the lesson: https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/digitsum.
The question I want to ask is why does it not accept an answer just by using the sum format? Like so:
def digit_sum(n): return sum(n) print digit_sum([1,2,3,4])
As it still prints out 10 as the correct answer, it’s just the argument is entered as a list of arguments, rather then one argument, which then has to be turned into a string then concatenated together and then turned into an int, or the other way round. Even if the argument isn’t entered as a list when calling the function:
print digit_sum(1234) an error is generated saying: int object is not iterable, I don’t know why this happens? Is it because python sees the argument as one object, and therefore cannot add it up, because it has nothing to add up?