Digit_Sum


#1

Here’s a link to the exercise:
https://www.codecademy.com/courses/python-intermediate-en-rCQKw/0/4?curriculum_id=4f89dab3d788890003000096

I keep getting this error and can’t figure out what’s wrong: Oops, try again. Does your digit_sum function take exactly one argument (a positive integer)? Your code threw a “‘int’ object is not iterable” error.

Any ideas?

Here’s my code:

def digit_sum(n):
    str(n)
    numbers = []
    answer = 0
    for let in n:
        numbers.append(let)
    for dig in numbers:
        int(dig)
        answer += dig
    return answer



#2

str(n) returns the integer as a string. So 1234 is converted into “1234”.

int(dig) returns the string digit as an integer. So a string of “1” is converted into an integer 1.

Now look at your code. You are converting them. But think about what it means to return a value. What happens to the value being returned? Where should be assigned?


#3

I have the same issue


#4

If you’ve any problems with this lesson then please create a new topic

you shouldn’t post on other’s topic.

Follow this link It’ll help you to create a new topic :slight_smile:


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.