Multiples of a number

Ivan Shevanski darkpaladin79 at gmail.com
Sun Nov 6 10:34:48 EST 2005


On 11/5/05, Steven D'Aprano <steve at removethiscyber.com.au> wrote:
>
> On Sun, 06 Nov 2005 02:39:40 +0100, Carl Friedrich Bolz wrote:
>
> > Hi!
> >
> > Ivan Shevanski wrote:
> >> I've searched on google for a bit but I can't seem to find a way to get
> >> multiples of a number. . .For instance what would I do if I wanted
> >> something to happen every time x reached a multiple of 100 in this
> >> sample code:
> >>
> >> x = 0
> >> while x < 2000:
> >> x += 1
> >>
> >
> > The idea is to use to modulo operator % which gives you the residue of a
> > number when divided by another number:
>
> > for x in range(2000):
> > if x % 100 == 0:
> > do_something()
>
> Another way is, if you aren't doing anything *except* counting for the
> other 99 values of x, just skip them completely:
>
> fox x in range(20):
> do_something(x*100)
>
>
> Ivan, what are you trying to do?
>
>
> --
> Steven.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Sorry for the late response. What I'm doing is pretty simple, I just have a
counter running and every time the counter gets to a multiple of 100 it runs
a function. So Carl's solution will work fine. Thanks everyone!


Thanks,

-Ivan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051106/802e521b/attachment.html>


More information about the Python-list mailing list