[Tutor] Tutor Digest, Vol 132, Issue 51

Danny Yoo danny.yoo at gmail.com
Sat Feb 21 18:04:26 CET 2015


On Feb 21, 2015 8:49 AM, "Tim Johnson" <pavementii at gmail.com> wrote:
>
> Hi Guys,
> Very simple question, I imagine.
>
> this code throws of off a "counter not defined error".
> Can you help?
>
> *def word_counter(word, string):*
> *    counter = 0*
> *    for item in string:*
> *        if item == word:*
> *            counter = counter + 1*
> *print counter*

Hmmm...  I don't understand what the intent of the last line of the program
is.  Can you explain what you're trying to do there?

Do you intend to do this print after the for loop?  If so, it should still
be scoped to the function though.  At the moment, it is a statement that's
entirely separate from the function definition.

Good luck!


More information about the Tutor mailing list