[Tutor] need help with python for counter

DoanVietTrungAtGmail doanviettrung at gmail.com
Wed Dec 19 07:13:36 CET 2012


After incrementing for a little while, if the condition i == digit is not
met for the current character, count is reset by the else: branch. Your
count variable must feel frustrated like a dog which keeps being yanked
back by a cord of length 0 when it tries to get free.

Trung Doan
==========

On Wed, Dec 19, 2012 at 4:40 PM, Brandon Merritt <merrittb7 at gmail.com>wrote:

> I feel silly, but I'm having the darndest time trying to figure out why
> this for counter won't work. I know that there is the count method for the
> string class, but I was just trying to do it the syntactical way to prove
> myself that I know the very basics. As of right now, my script is just
> returning 1 or 0, even if I very clearly make sure that I specify at least
> 4 instances of the digit in my number string:
>
> number = raw_input('Enter a 7-unit number: ')
>
> digit = raw_input('Enter a single digit: ')
>
> for i in number:
>     count = 0
>     if i == digit:
>         count += 1
>     else:
>         count = 0
>
> print count
>
> Thanks,
> Brandon
>
>
> --
> *Brandon Merritt**
> (707) 481-1744*
> *
> *
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121219/3f0855bc/attachment-0001.html>


More information about the Tutor mailing list