I am getting the output for the program but not in the required way?
<p>Write a Python function that accepts a string as an input.
The function must return the sum of the digits 0-9 that appear in the string, ignoring all other characters.Return 0 if there are no digits in the string.</p>

<p>my code:</p>

<pre><code>user_string = raw_input("enter the string: ")
new_user_string = list(user_string)
addition_list = []
for s in new_user_string:
    if ( not s.isdigit()):
        combine_string = "".join(new_user_string)
        print ( combine_string)
    else:
        if ( s.isdigit()):
            addition_list.append(s)
            test = "".join(addition_list)
            output = sum(map(int,test))
            print ( output )
</code></pre>

<p>the output should be:</p>

<pre><code>Enter a string: aa11b33
8
</code></pre>

<p>my output:</p>

<pre><code>enter the string: aa11b33
aa11b33
aa11b33
1
2
aa11b33
5
8
</code></pre>

<p>This look suspiciously like homework...</p>

<pre><code>getsum = lambda word: sum(int(n) for n in word if n.isdigit())

getsum('aa11b33')
Out[3]: 8

getsum('aa')
Out[4]: 0
</code></pre>

<p>An explanation of how this works piece-by-piece:</p>

<ol>
<li>The function <code>n.isdigit()</code> returns <code>True</code> if <code>n</code> is composed only of one or more digits, false otherwise. (<a href="https://docs.python.org/3/library/stdtypes.html#str.isdigit" rel="nofollow">Documentation</a>)</li>
<li>The syntax <code>for n in word</code> will loop over each item in the iterable <code>word</code>. Since <code>word</code> is a string, python considers each character to be an individual item.</li>
<li>The operation <code>sum(int(n) for n in word...)</code> casts each character to an <code>int</code> and takes the sum of all of them, while the suffix <code>if n.isdigit()</code> filters out all non-digit characters. Thus the end result will just take the sum of all the individual digit characters in the string <code>word</code>.</li>
<li>The syntax <code>lambda x: some expression using x</code> constructs an anonymous function which takes some value <code>x</code> as its parameter, and returns the value of the expression after the colon. To give this function a name we can just put it on the right-hand-side of an assignment statement. Then we can call it like a normal function. Usually it's better to use a normal <code>def getsum(x)</code> kind of function definition, however <code>lambda</code> expressions are sometimes useful for if you have a one-off kind of function you just need to use as a parameter to a function. In general in python it's better if you can find a way to avoid them, as they're not considered very readable.</li>
</ol>

<p>Here is a complete example:</p>

<pre><code>def sumword(word):
    return sum( int(n) for n in word if n.isdigit() )

word = raw_input("word please: ")
print(sumword(word))
</code></pre>

python python-2.7 python-3.x ipython