Adding numbers in a string
<p>I have a string as an input for the code I'm writing and let an example of the string be: </p>

<pre><code>"12 inches  makes   1   foot"
</code></pre>

<p>My goal is to have my code run through this string and just pull out the integers and add them. So the output for the string above would be 13. I am using try and except in here as well since another sample input string could be something like "pi is 3.14". </p>

<pre><code>msg= "12    inches  makes   1   foot"

thesum = 0

s= msg.split()

for a in s:

    try:

        if a == int(a):
            a= int(a)
            thesum += a
        print (thesum)
    except ValueError as e:


        print("Value Error: no int present")
</code></pre>

<p>I did what is above and I am not getting it to add the value of a (if it is an int) to "thesum". How can I get this to work? Also, I do want to have it in the try, except format so that I can call the ValueError </p>