(python and jes) How to find the position of a character in a string if 2 characters are the same?
<pre><code>def sumNumbers1(num1,num2):
    sum= str(num1+num2)
    print "Sum is " + sum
    for char in sum:
        digit = sum.find(char)+1
        print "Digit " + str(digit) + " is " + char
</code></pre>

<p>I'm trying to get a function that prints the sum of two numbers, then the first digit of the sum and what that character is, and so on for each digit. However, if the sum is a number with two of the same characters, (77 for example), my function prints "Sum is 77 Digit 1 is 7
 Digit 1 is 7" I realize this is an issue with index but how do I fix it? Thanks!</p>

<p>You likely want to use <code>enumerate</code>.  <code>sum</code> is a string, enumerate will let you iterate over the characters in that string while also returning the index of each character.  Python indexing is 0-based, so if you want the <em>digit</em> index to start at 1, you need to add 1 to <code>i</code></p>

<pre><code>for i, char in enumerate(sum):
    print "Digit " + str(i+1) + " is " + char
</code></pre>

python jes