Looping and Counting w/find
<p>So I am working diligently on some examples for my homework and came across yet another error.</p>

<p>The original:</p>

<pre><code>    word = 'banana'
    count = 0
    for letter in word:
        if letter == 'a':
            count = count + 1
    print count
</code></pre>

<p>Ok. Looks simple.</p>

<p>I then used this code in a function name <em>count</em> and generalized it so that it accepts the string and the letter as argument.</p>

<pre><code>    def count1(str, letter):
        count = 0             
        word = str            
        for specific_letter in word: 
            if specific_letter == letter: 
                count = count + 1 

        print count
</code></pre>

<p>This is where I'm still not sure what I'm doing wrong.</p>

<p>I have to rewrite this function so that instead of traversing the string, it uses the three-parameter version of find from the previous section. Which this is:</p>

<pre><code>    def find(word, letter, startat):
        index = startat
        while index &lt;= len(word):
            if word[index] == letter:
                return index
            index = index + 1


        return -1
</code></pre>

<p>This is how far I got... but the program doesn't work the way I want it to.</p>

<pre><code>    def find(str, letter, startat):
        index = startat
        word = str   
        count = 0
        while index &lt;= len(word):
            if word[index] == letter:
                for specific_letter in word:
                    if specific_letter == letter:
                        count = count + 1

                print count
            index = index + 1
</code></pre>

<p>Can someone point me in the right direction. I want to understand what I'm doing instead of just given the answer. Thanks.</p>
